title: Expressjs redirecting to https (using Cloudflare Flexible SSL)
body: <p>im using Expressjs (NodeJS framework) and I want to redirect all traffic to https, im not using SSL certificates but Cloudflare flexible ssl.</p>
  
  <p>Im using this middleware:</p>
  
  <pre><code>//FORCE SSL
  app.use(function(req, res, next) {
    if(!req.secure) {
      return res.redirect(['https://', req.get('Host'), req.url].join(''));
    }
    next();
  });
  </code></pre>
  
  <p>And im launching the app this way:</p>
  
  <pre><code>//Firing Up express
  //====================================================================
  app.set('port', process.env.PORT || 80);
  var server = app.listen(app.get('port'), function() {
     console.log('[-]');
     console.log(('[+] Express server listening on port '+ server.address().port).green);
     console.log('[-]');
  });
  </code></pre>
  
  <p>The application redirects to https:// but then fail to load</p>
  
  <p>Google Chrome console says:</p>
  
  <pre><code>Failed to load resource: net::ERR_CONNECTION_REFUSED https://beta.domain.io/
  Failed to load resource: net::ERR_CONNECTION_CLOSED https://beta.domain.io/
  Failed to load resource: net::ERR_CACHE_MISS 
  </code></pre>
  
  <p>Can someone point me in the right direction?</p>
  
  <p>Thanks in advance.</p>