Los Angeles, CA

Node.js Force SSL in production

Node.js Force SSL in production

function requireHTTPS(req, res, next) {
if (req.headers['x-forwarded-proto'] == 'https') {
return next();
} else {
res.redirect('https://' + req.headers.host + req.path);
if (app.get('env') != 'development') app.use(requireHTTPS);

What failed for me initially was the check for

  • req.secure
  • req.protocol
  • req.connection.encrypted

None of those worked.

BTW check out sending a text from node.js
Somebody said they were looking for angular.js developer jobs
Well they should read my blog more 😛

Facebook Comments