Last active
February 28, 2017 10:12
-
-
Save martisj/08f30570fd1204b564a54d53174ef1a2 to your computer and use it in GitHub Desktop.
HTTPS redirect express.js node kind of specifically for Heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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