I have a NodeJS HTTP (non S) server running on Heroku. I have SSL configured, and it accepts requests to HTTPS. The reason I am using a vanilla HTTP server is because of the following:
SSL termination occurs at Heroku's load balancers; they send your app plain (non-SSL) traffic, so your app should create a non-HTTPS server."
Unfortunately, my app still responds to plain-old HTTP requests. I want to force a redirect or something from HTTP to HTTPS. I could do this with some middleware:
/* At the top, with other redirect methods before other routes */
app.get('*',function(req,res,next){
if(req.headers['x-forwarded-proto']!='https')
res.redirect('https://mypreferreddomain.com'+req.url)
else
next() /* Continue to other routes if we're not redirecting */
})
But is this a good solution? How do POST requests work? If I post to HTTP, should it be allowed?
The other final approach I was thinking, was to use Nginx and stick a redirect in there from HTTP to HTTPS. Unfortunately Heroku doesn't allow Nginx configs.