Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatic HTTPS connection/redirect with node.js/express
    primarykey
    data
    text
    <p>I've been trying to get HTTPS set up with a node.js project I'm working on. I've essentially followed the <a href="http://nodejs.org/docs/v0.4.11/api/https.html">node.js documentation</a> for this example:</p> <pre><code>// curl -k https://localhost:8000/ var https = require('https'); var fs = require('fs'); var options = { key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') }; https.createServer(options, function (req, res) { res.writeHead(200); res.end("hello world\n"); }).listen(8000); </code></pre> <p>Now, when I do </p> <pre><code>curl -k https://localhost:8000/ </code></pre> <p>I get </p> <pre><code>hello world </code></pre> <p>as expected. But if I do </p> <pre><code>curl -k http://localhost:8000/ </code></pre> <p>I get </p> <pre><code>curl: (52) Empty reply from server </code></pre> <p>In retrospect this seems obvious that it would work this way, but at the same time, people who eventually visit my project aren't going to type in <strong>https</strong>://yadayada, and I want all traffic to be https from the moment they hit the site. </p> <p>How can I get node (and Express as that is the framework I'm using) to hand off all incoming traffic to https, regardless of whether or not it was specified? I haven't been able to find any documentation that has addressed this. Or is it just assumed that in a production environment, node has something that sits in front of it (e.g. nginx) that handles this kind of redirection?</p> <p>This is my first foray into web development, so please forgive my ignorance if this is something obvious.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload