Skip to content

Instantly share code, notes, and snippets.

@martisj

martisj/app.js

Last active Feb 28, 2017
Embed
What would you like to do?
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