You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am new to digitalocean app platform. I have created a simple hello world golang application and tried to deploy it with digitalocean. But I am getting Deploy Error: Health checks. The reason im posting this in this repo, is that, this repo works perfectly fine with digitalocean app platform. But mine one doesnt. I need to know which step am I missing.
my go.mod file:
module github.com/tawsifkarim/do-app
go 1.17
require github.com/gorilla/mux v1.8.0
Here is my code:
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/", rootHandler)
port := os.Getenv("PORT")
if port == "" {
port = "80"
}
fmt.Println("starting server at port:", port)
err := http.ListenAndServe("localhost:"+port, r)
if err != nil {
log.Fatal("Something went wrong starting the server", err)
}
}
type Person struct {
Name string `json:"name"`
Purpose string `json:"purpose"`
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
x := Person{
Name: "tawsif",
Purpose: "testing do app platform",
}
bt, err := json.Marshal(x)
if err != nil {
fmt.Println("json marshal error", err.Error())
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(bt)
}
The text was updated successfully, but these errors were encountered:
@TawsifKarim I know this is really late, but the issue is your ListenAndServe call, you shouldn't specify localhost. That is a loopback interface and is not exposed externally. You can read more in "How to Troubleshoot Apps in App Platform", specifically the HTTP Service on localhost vs 0.0.0.0.
fmt.Println("starting server at port:", port)
- err := http.ListenAndServe("localhost:"+port, r)+ err := http.ListenAndServe(":"+port, r)
if err != nil {
log.Fatal("Something went wrong starting the server", err)
}
Hello, I am new to digitalocean app platform. I have created a simple hello world golang application and tried to deploy it with digitalocean. But I am getting Deploy Error: Health checks. The reason im posting this in this repo, is that, this repo works perfectly fine with digitalocean app platform. But mine one doesnt. I need to know which step am I missing.
my go.mod file:
Here is my code:
The text was updated successfully, but these errors were encountered: