Using Golang, I wrote this basic server:
func main() {
router := gin.Default()
router.GET("/api", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"data": "hello world"})
})
router.LoadHTMLGlob("www/*.html")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", nil)
})
fmt.Println("listening on localhost:8080")
router.Run("localhost:8080")
}
It works fine running on localhost.
After I deploy with sudo gcloud app deploy, I browse to the hosting url route for the main page and with static files works fine, but when I browse to /api route it throws Page not found error (which works locally)
Here is the app.yaml used for deploying to App Engine:
runtime: go116
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
What I have tried:
- Enabling Cloud Build API
- Enabling App Engine Admin API
- Using migrate traffic feature from Cloud Console in App Engine to set the default version
What am I doing wrong here?
Note: The Go version I run on localhost is 1.17 but App Engine supports up to version 1.15