Skip to content

Instantly share code, notes, and snippets.

@martisj
Last active February 28, 2017 10:12
Show Gist options
  • Save martisj/08f30570fd1204b564a54d53174ef1a2 to your computer and use it in GitHub Desktop.
Save martisj/08f30570fd1204b564a54d53174ef1a2 to your computer and use it in GitHub Desktop.
HTTPS redirect express.js node kind of specifically for Heroku
const express = require('express');
const app = express();
app.use((req, res, next) => {
if (req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production') {
res.redirect(`https://${req.hostname}${req.url}`);
} else {
next();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment