Disable default domain https://[project-id].appspot.com of Node JS on Google App Engine

前端 未结 3 2015
小蘑菇
小蘑菇 2020-12-20 21:21

I have deployed my Node JS app onto Google Cloud App Engine, and I can successfully add my custom domain for my app.

Let say my custom domain is example.com

3条回答
  •  心在旅途
    2020-12-20 22:09

    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.

    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);
    });
    

提交回复
热议问题