【发布时间】:2021-12-30 12:04:18
【问题描述】:
使用 Golang,我编写了这个基本服务器:
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")
}
它在本地主机上运行良好。
使用sudo gcloud app deploy 部署后,我浏览到主页的托管 url 路由,静态文件可以正常工作,但是当我浏览到/api 路由时,它会抛出Page not found 错误(在本地工作)
这是用于部署到 App Engine 的 app.yaml:
runtime: go116
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
我尝试过的:
- Enabling Cloud Build API
- Enabling App Engine Admin API
- Using migrate traffic feature from Cloud Console in App Engine to set the default version
我在这里做错了什么?
注意:我在 localhost 上运行的 Go 版本是 1.17 但App Engine supports up to version 1.15
【问题讨论】:
标签: go google-app-engine google-cloud-platform