I am trying to create a middleware for Express.js to redirect all non-secure (port 80) traffic to the secured SSL port (443).
Unfortunately there is no information in an Express.js request that lets you determine if the request comes over http or https.
One solution would be to redirect every request but this is not an option for me.
Notes:
-
There is no possibility to handle it with Apache or something else. It has to be done in node.
-
Only one server can be fired up in the application.
How would you solve that?
Since I was working on nginx, I had access to the header’s x-forwarded-proto property so I could write a tiny middleware to redirect all traffic as described here: http://elias.kg/post/14971446990/force-ssl-with-express-js-on-heroku-nginx
Edit: Updated the url