How do I prevent the “appspot.com” of my App Engin

2020-05-02 00:05发布

I have a custom domain added that I added to App Engine. For example, let's say my custom domain is "example.com". My app is served with Node.js, and I when I deploy my app through App Engine, it gives me this address to access to it:

"example.appspot.com".

How do I prevent this? I want to serve my app only on "example.com".

SOLVED: I'm using this middleware to prevent those hostnames and it works, at least for what I kind of wanted:

var redirect = function(req, res, next) {
    if (req.hostname.search('appspot') !== -1) {
        res.redirect(301, 'https://www.example.com');
        next();
    }
    next();
};

app.use(redirect);

0条回答
登录 后发表回答