Skip to content

Instantly share code, notes, and snippets.

@fehguy
Created September 29, 2015 06:21
Show Gist options
  • Save fehguy/3dd5e8f57be446034584 to your computer and use it in GitHub Desktop.
Save fehguy/3dd5e8f57be446034584 to your computer and use it in GitHub Desktop.
redirect
////////
// HTTPS
if(config.PRODUCTION) {
app.use(function(req, res, next) {
if((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) {
res.redirect('https://' + req.get('Host') + req.url);
}
else
next();
});
}
////////
// non-root domains
if(config.PRODUCTION) {
app.use(function(req, res, next) {
if(req.get('Host').toLowerCase().indexOf('swaggerhub') !== 0) {
res.redirect('https://swaggerhub.com' + req.url);
}
else
next();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment