I have deployed my Node JS app onto Google Cloud App Engine, and I can successfully add my custom domain for my app.
我已经将Node JS应用部署到谷歌云应用引擎上,我可以成功的为我的应用添加我的自定义域。
Let say my custom domain is example.com.
假设我的自定义域名是example.com。
Now I can browse my app via example.com & www.example.com, it works as expected. But I find that I can still browse my app through the default domain. https://[project-id].appspot.com
现在我可以通过example.com和www.example.com浏览我的应用程序,它可以正常工作。但是我发现我仍然可以通过默认域浏览我的应用。https://[项目id].appspot.com
I want to disable the default domain, is it possible to do that?
我想禁用默认域,有可能吗?
3 个解决方案
#1
0
You cannot disable that default domain. You would have to write a redirect script. You can test for "appspot" in the request's HTTP_HOST
, and test for "AppEngine-Google" in the request's HTTP_USER_AGENT
, to determine if it is an internal request.
不能禁用该默认域。您将不得不编写一个重定向脚本。您可以在请求的HTTP_HOST中测试“appspot”,在请求的HTTP_USER_AGENT中测试“AppEngine-Google”,以确定它是否是一个内部请求。
Also, internal functions, like cron jobs and task queues, run on that domain, so be careful what you do. Task queues will fail given a 301.
此外,内部函数,如cron作业和任务队列,在该域中运行,所以要小心。给定301任务队列将失败。
#2
1
After considering GAEfan suggestion, I have made some change on the router logic. If the host name is ended with "appspot.com" and the user agent is included "AppEngine-Google", it will redirect to my custom domain.
在考虑了GAEfan的建议后,我对路由器逻辑做了一些修改。如果主机名以“appspot.com”结尾,而用户代理包括“AppEngine-Google”,则它将重定向到我的自定义域。
router.get('/', function(req, res, next) {
if(req.get("host").endsWith(GOOGLE_APP_SPOT) &&
req.get("User-Agent").includes(GOOGLE_USER_AGENT))
{
var redirectURL = url.format({
protocol: req.protocol,
host: CUSTOM_DOMAIN,
pathname: req.originalUrl
});
res.redirect(redirectURL);
}
res.render('templateName', viewModel);
});
#3
1
You can do it just using the dispatch.yaml
file from App Engine, list all your domains there, but not the *.appspot.com
one. Google will show a 404 route when you try to access that.
只需使用分派即可。来自App Engine的yaml文件,列出所有您的域,但不列出*.appspot.com。当您试图访问该路径时,谷歌将显示一个404路径。
Checkout the official reference.
结账的官方参考。
#1
0
You cannot disable that default domain. You would have to write a redirect script. You can test for "appspot" in the request's HTTP_HOST
, and test for "AppEngine-Google" in the request's HTTP_USER_AGENT
, to determine if it is an internal request.
不能禁用该默认域。您将不得不编写一个重定向脚本。您可以在请求的HTTP_HOST中测试“appspot”,在请求的HTTP_USER_AGENT中测试“AppEngine-Google”,以确定它是否是一个内部请求。
Also, internal functions, like cron jobs and task queues, run on that domain, so be careful what you do. Task queues will fail given a 301.
此外,内部函数,如cron作业和任务队列,在该域中运行,所以要小心。给定301任务队列将失败。
#2
1
After considering GAEfan suggestion, I have made some change on the router logic. If the host name is ended with "appspot.com" and the user agent is included "AppEngine-Google", it will redirect to my custom domain.
在考虑了GAEfan的建议后,我对路由器逻辑做了一些修改。如果主机名以“appspot.com”结尾,而用户代理包括“AppEngine-Google”,则它将重定向到我的自定义域。
router.get('/', function(req, res, next) {
if(req.get("host").endsWith(GOOGLE_APP_SPOT) &&
req.get("User-Agent").includes(GOOGLE_USER_AGENT))
{
var redirectURL = url.format({
protocol: req.protocol,
host: CUSTOM_DOMAIN,
pathname: req.originalUrl
});
res.redirect(redirectURL);
}
res.render('templateName', viewModel);
});
#3
1
You can do it just using the dispatch.yaml
file from App Engine, list all your domains there, but not the *.appspot.com
one. Google will show a 404 route when you try to access that.
只需使用分派即可。来自App Engine的yaml文件,列出所有您的域,但不列出*.appspot.com。当您试图访问该路径时,谷歌将显示一个404路径。
Checkout the official reference.
结账的官方参考。