0

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);
franfonse
  • 189
  • 1
  • 3
  • 10
  • Prevent what? Remove the domain `example.appspot.com`? Prevent access using the domain `exmple.appspot.com`? Redirect visitors to `www.example.com`? Edit your question with details on what you are asking. – John Hanley Mar 26 '20 at 02:06
  • sorry, I just edited. – franfonse Mar 26 '20 at 02:20
  • 2
    Code your app to check the HTTP Host request header based on the domain name and then respond accordingly with a redirect specifying an HTTP Location header in the response. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location – John Hanley Mar 26 '20 at 02:40
  • For example use this command to see how the Location header is used: `curl -i http://www.jhanley.com` – John Hanley Mar 26 '20 at 02:41
  • 2
    Possibly of interest: comments to https://stackoverflow.com/questions/57545133/disabling-version-specific-urls-in-google-appengine/57545687#57545687 – Dan Cornilescu Mar 26 '20 at 03:36
  • 1
    Before choosing your strategy, read @DanCornilescu answer plus the comments. You probably do not want to drop/redirect the `appspot.com` domain completely. – John Hanley Mar 26 '20 at 04:09
  • Thanks, I will try to make that work with the 301 relocate, not so familiar with it but will try to do. – franfonse Mar 27 '20 at 21:15
  • https://stackoverflow.com/a/60883838/11392389 – franfonse Mar 27 '20 at 21:27

0 Answers0