Skip to content

Instantly share code, notes, and snippets.

@nakedible-p
Created May 15, 2018 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakedible-p/bac73a34eb3e3e2c637f80e14e839b7f to your computer and use it in GitHub Desktop.
Save nakedible-p/bac73a34eb3e3e2c637f80e14e839b7f to your computer and use it in GitHub Desktop.
HTTP to HTTPS redirect
require('http').createServer((req, res) => {
const host = req.headers['x-forwarded-host'] || req.headers.host;
res.setHeader('Location', `https://${host}${req.url}`);
res.statusCode = 301;
res.end();
}).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment