0

I'm trying to configure HTTPS for my Express server. I found the following code from this question's answers.

console.log("Test 1");
var httpServer = http.createServer(app);
console.log("Test 2");
var httpsServer = https.createServer(credentials, app);
console.log("Test 3");
httpServer.listen(8080);
console.log("Test 4");
httpsServer.listen(8443);
console.log("Test 5");

Problem is the only thing that appears in the console is Test 1 and Test 2. Nothing after that line seems to be running. I basically just want the same Express app to run on both HTTP and HTTPS.

In the past I just used server = app.listen(port); to start the Express server.

Any ideas?

EDIT

The Node app continues to run with no errors but just doesn't print those final console.log statements.

var fs = require('fs');
var privateKey  = fs.readFileSync('ssl/servertest.key', 'utf8');
var certificate = fs.readFileSync('ssl/servertest.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};

servertest.key and servertest.crt.

Note: I know putting those online and making them public is a bad idea. Just using it for example. Before going into production I'm going to regenerate the SSL keys.

Community
  • 1
  • 1
Charlie Fish
  • 18,491
  • 19
  • 86
  • 179
  • All that code in node would get executed asynchronously, so I'm assuming you have an error in your createServer(credentails what's have you got in credentials? – Keith Oct 05 '16 at 22:58
  • @Keith No error was logged in the terminal or anything – Charlie Fish Oct 05 '16 at 22:59
  • Strange,.. Does the node App stop, do you have valid key & cert in your credentials?.. I use Express HTTPS without any problems. Could you knock up a quick demo of what you've done? – Keith Oct 05 '16 at 23:01
  • @Keith Just made a few edits to try to describe it better. – Charlie Fish Oct 05 '16 at 23:09
  • Your private key is password protected.. – Keith Oct 05 '16 at 23:20
  • @Keith Great looks like that worked! One more question. I'm currently using `server.close`. I can just use `httpServer.close` and `httpsServer.close` since I don't have server anymore correct? Also feel free to leave an answer and I will up vote and accept it. – Charlie Fish Oct 05 '16 at 23:28
  • Yes, you can just do httpServer.close(), – Keith Oct 05 '16 at 23:33

1 Answers1

1

Yes, the private key was password protected.

On my system I was getting the error,

Error: error:0906A068:PEM routines:PEM_do_header:bad password read

not sure why you wasn't, maybe it's node version.

Here you have 2 options, either remove the password from the key using openSSL, or supply the password to the options via the passphrase option.

Keith
  • 22,005
  • 2
  • 27
  • 44