I built small go app, which I run locally using the following
// +build !appengine
package main
import (
"fmt"
"net/http"
"github.com/Test/test/server"
)
func main() {
r := server.Router()
fmt.Println("Started Server")
http.ListenAndServe("localhost:8182", r)
}
I deployed this some ago to Google AppEngine, and the above doesn't work, so I created this for Google AppEngine:
// +build appengine
package main
import (
"net/http"
"github.com/Test/test/server"
"google.golang.org/appengine"
)
func init() {
r := server.Router()
appengine.Main()
http.Handle("/", r)
}
I use the following in app.yaml
handlers:
- url: /.*
script: _go_app
secure: always
redirect_http_response_code: 301
The app deploys fine, the Google Cloud Console says it is running, but all I get is "404 page not found", which is not any of the handlers that I built. AppEngine reports no errors, I only see 404 in the logs, digging deeper in the logs I find that some things mention the go app: urlMapEntry: "_go_app"
.
I am using go-chi router:
func Router() *chi.Mux {
r := chi.NewRouter()
// home
r.Get("/", handlers.RootHandler)
// api
r.Route("/api", func(r chi.Router) {
r.Get("/*", handlers.NotSupportedAPIHandler)
})
r.Get("/*", handlers.RootHandler)
})
return r
}
But not matter which url I enter, I do not see that the RootHandler
is getting used, because it would return an HTML file. When I try to access /api, I also not do see the NotSupportedAPIHandler
picking it up, since that would return a status 404 with a JSON response.
The strange thing is that a while back the code worked, I got the HTML file served, using the go_app, using the go-chi router. Now, all I get is 404 page not found.
The app is running fine locally.
How can I debug this? Is there any place where I can see what is going wrong or how app.yaml
is routing this in such a way that it finds it necessary to return the 404. Any response from my go_app would look different to what I am getting now, so this is why I think the failure is earlier, in app.yaml
.