|
|
|
Ask HN: Create http or https server for Node.js on Heroku
|
|
1 points
by amend
3022 days ago
|
|
I can’t find out if I’m supposed to create an http or https server for node.js hosted on heroku. Apparently, paid heroku apps now handle ssl and receives over https by default. When the app receives an https request, the heroku load balancers convert the request to http and then send the request to your app. So it seems that heroku handles https/ssl for you, and all we have to do is set up a http app. If the request is sent from the client as http, the following code should be added to ensure encryption on data sent. /* Redirect http to https /
app.get('', function(req,res,next) {
if(req.headers['x-forwarded-proto'] != 'https' && process.env.NODE_ENV === 'production')
res.redirect('https://'+req.hostname+req.url)
else
next() /* Continue to other routes if we're not redirecting */
}); Am I incorrect that that we should use an http app over https because heroku handles encryption? |
|