douhuan1497 2018-03-23 09:27
浏览 56

在运行go app的app引擎上显示404

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制