
Ask HN: Create http or https server for Node.js on Heroku - amend
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&#x2F;ssl for you, and all we have to do is set up a http app.<p>If the request is sent from the client as http, the following code should be added to ensure encryption on data sent.<p>&#x2F;* Redirect http to https <i>&#x2F;
app.get(&#x27;</i>&#x27;, function(req,res,next) {
  if(req.headers[&#x27;x-forwarded-proto&#x27;] != &#x27;https&#x27; &amp;&amp; process.env.NODE_ENV === &#x27;production&#x27;)
    res.redirect(&#x27;https:&#x2F;&#x2F;&#x27;+req.hostname+req.url)
  else
    next() &#x2F;* Continue to other routes if we&#x27;re not redirecting *&#x2F;
});<p>Am I incorrect that that we should use an http app over https because heroku handles encryption?
======
eberkund
This seems more appropriate for Stackoverflow

~~~
amend
Yes, I agree. I posted the question here too because the last time I asked a
question, the responses provided excellent answers and related conversations.
Should I remove it from HN?

