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.

7
  • 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? Commented Oct 5, 2016 at 22:58
  • @Keith No error was logged in the terminal or anything Commented Oct 5, 2016 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? Commented Oct 5, 2016 at 23:01
  • @Keith Just made a few edits to try to describe it better. Commented Oct 5, 2016 at 23:09
  • Your private key is password protected.. Commented Oct 5, 2016 at 23:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.