Tuesday 14 March 2017

Handling error on https.createServer() in Node.JS/Express.JS not working

I have been trying to implement handling errors in our Node.JS app when there is an error when we do https.createServer().

I found this thread:

Node.js http.createServer how to get error

but I cannot seem to make it work :(...

Here is my code:

var fs = require('fs');
var https = require('https');
// Setup HTTPS
var options = {
  pfx: fs.readFileSync('../security/server.pfx'),
  passphrase: XXXXX
};
console.log("++++++++ Listen SSL Mode ++++++++");
var secureServer = https.createServer(options, app);
secureServer.on('error', function (e) {
    // Handle your error here
    console.log(e);
    });
secureServer.listen(LISTENPORT);

When I try that, it's like the "secureServer.on()' is not being processed at all:

++++++++ Listen SSL Mode ++++++++
_tls_common.js:137
      c.context.loadPKCS12(pfx, passphrase);
                ^

Error: mac verify failure
    at Error (native)
    at Object.createSecureContext (_tls_common.js:137:17)
    at Server (_tls_wrap.js:768:25)
    at new Server (https.js:26:14)
    at Object.exports.createServer (https.js:47:10)

Can someone tell me what I might be doing wrong?

Thanks, Jim



via user555303

No comments:

Post a Comment