Note that there are some explanatory texts on larger screens.

plurals
  1. POHeroku Error H13 on ExpressJS Node HTTPS Server
    primarykey
    data
    text
    <p>I'm trying to implement HTTPS on my Node.js server (Expressjs framework). I have my signed certificate and key, as well as a self-signed cert/key for testing/development:</p> <pre><code>if(process.env.NODE_ENV == 'production'){ var app = module.exports = express.createServer({ key: fs.readFileSync('./ssl/nopass_server.key'), cert: fs.readFileSync('./ssl/server.crt') }); } else { var app = module.exports = express.createServer({ key: fs.readFileSync('./ssl/self_signed/nopass_server.key'), cert: fs.readFileSync('./ssl/self_signed/server.crt') }); } </code></pre> <p>I've also setup SSL Endpoint on Heroku. Everything works fine on <code>localhost</code>, and Endpoint seems to be working properly, but when I run the app in production (on Heroku) I get an H13 application error. Interestingly (or not) if I tell express to create an HTTP server instead: <code>var app = module.exports = express.createServer()</code> it works, but then Chrome complains that <code>the page at https://mydomain.com ran insecure content from http://mydomain.com</code>.</p> <p>Can I not/should I not be creating an HTTPS server in express for production? If I should, is there something extra I need to make it work on Heroku (e.g. I'm trusting it to set the correct port with <code>var port = process.env.PORT</code>)? If not, how can I serve "secure" content if its not running an https server so browsers won't complain? </p> <p>I'm using the following to take care of any non-https requests:</p> <pre><code>app.get('*',function(req,res,next){ if(req.headers['x-forwarded-proto'] != 'https'){ res.redirect('https://mydomain.com'+req.url); } else next(); }); </code></pre> <p>This is currently located just above the rest of my routes, could this be the issue/should this be somewhere else?</p> <p>I have very limited experience with https in general so I'm probably missing 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.
    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