Google app engine 谷歌应用引擎自定义域-Go中的路由
我一直在利用谷歌应用程序引擎提供给我的url,即“projectname-id.appspot.com”来完成我的项目。我之前从GoDaddy购买了一个自定义域,我按照以下链接中的步骤验证了Google云平台中域名的所有权,将该域添加到我的Google App Engine项目,并在GoDaddy中更新我的DNS设置,以指向列出的CNAME/服务器组合 当我访问我的自定义域时,会提供一个网站页面,但它始终是404。“projectname-id.appspot.com”url仍然正常工作,当我查看Google应用程序引擎中的日志语句时,它接收到来自我的自定义域和appspot域的请求-这似乎表明域dns已正确更新。请参见下图,其中404来自自定义域,200来自appspot url: 我还有别的事要做吗?后端是用Go编写的,我们使用的是Mux路由器。我是否需要修改app.yaml文件或以某种方式编辑我的路线?如有任何建议,将不胜感激 这里我包含了一些用于初始化服务器的代码片段: App.yamlGoogle app engine 谷歌应用引擎自定义域-Go中的路由,google-app-engine,go,dns,subdomain,Google App Engine,Go,Dns,Subdomain,我一直在利用谷歌应用程序引擎提供给我的url,即“projectname-id.appspot.com”来完成我的项目。我之前从GoDaddy购买了一个自定义域,我按照以下链接中的步骤验证了Google云平台中域名的所有权,将该域添加到我的Google App Engine项目,并在GoDaddy中更新我的DNS设置,以指向列出的CNAME/服务器组合 当我访问我的自定义域时,会提供一个网站页面,但它始终是404。“projectname-id.appspot.com”url仍然正常工作,当我查
version: alpha-001
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
env_variables:
PRODUCTION: 'TRUE'
DATASTORE_DATASET: 'app-id'
DATASTORE_HOST: 'http://localhost:8043'
DATASTORE_EMULATOR_HOST: 'localhost:8043'
DATASTORE_PROJECT_ID: 'app-id'
GOOGLE_APPLICATION_CREDENTIALS: './app-string.json'
正在初始化WebConsole(服务器):
WebConsole.go
type WebConsole struct {
prod bool
Mux *mux.Router
DbMap *gorp.DbMap
Client *datastore.Client
}
func NewWebConsole(prod bool) *WebConsole {
return &WebConsole{
prod: prod,
}
}
func (w *WebConsole) Run() {
w.dbInit()
w.routesInit()
}
func (w *WebConsole) dbInit() {
// Configure SQL connection
// Code removed for privacy reasons
}
func (w *WebConsole) routesInit() {
// Configure routes with Mux
w.Mux = mux.NewRouter()
api.AddCertChallengeApis(w.Mux)
// The path "/" matches everything not matched by some other path.
// Checkout: http://stackoverflow.com/questions/26581231/google-cloud-go-handler-without-router-gorilla-mux
// for more details
http.Handle("/", w.Mux)
}
用于路由的Api包文件
package api
import (
"github.com/gorilla/mux"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
"net/http"
"strings"
)
func AddCertChallengeApis(r *mux.Router) {
r.Schemes("http")
r.HandleFunc("/", defaultHandler())
}
func defaultHandler() http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
// Construct new app engine context
c := appengine.NewContext(req)
log.Infof(c, "App ID: %v", appengine.AppID(c))
rw.Header().Set("Content-Type", "text/plain")
rw.Write([]byte("hi, welcome to my website yo"))
log.Infof(c, "Hit the website")
}
}
我以前在appengine/go上做过自定义域,您不需要做其他事情。不过我会试着去掉这条线
r.Schemes("http")
以防它与https相关。我以前在appengine/go上做过自定义域,您不需要做任何其他事情。不过我会试着去掉这条线
r.Schemes("http")
如果它与https相关。我是否必须在GoDaddy DNS注册器端添加任何类型的转发(CNAME条目除外)?您是否有任何可共享、工作gae自定义域代码的示例?我是否必须在GoDaddy DNS注册器端添加任何类型的转发(CNAME条目除外)?您是否有任何可共享、可工作的gae自定义域代码的示例?