I am running node v4.1.1 and npm 2.14.4 on Mac OS X. For the same express app I want to launch an http and https server. The http one runs just perfect, but the other crashes with the consequent error:
if (process.features.tls_npn && !opts.NPNProtocols) {
^
TypeError: Cannot read property 'NPNProtocols' of undefined
at new Server (https.js:13:40)
at Object.exports.createServer (https.js:37:10)
The following code runs the whole express app and invokes http methods:
#!/usr/bin/env node
var app = require('./src')
, config = require('./config')
, cmd = require('commander')
, http = require('http')
, https = require('https')
, path = require('path')
cmd
.version('0.1.42')
.option('-p, --port <n>', 'Port to start the HTTP server', parseInt)
.parse(process.argv)
// Launch server with web sockets
var server = http.createServer(app)
var sslServer = https.createServer({
key: fs.readFileSync('ryans-ley.pem'),
cert: fs.readFileSync('ryans-cert.pem')
}, app)
// Listen on provided port, on all network interfaces.
server.listen(config.port || cmd.port, function () {
console.log('http marketplace started on %s:%s',
server.address().address,
server.address().port)
})
sslServer.listen(443, function () {
console.log('https marketplace started on %s:%s',
sslServer.address().address,
sslServer.address().port)
})
Those certs have been generated with this guide: https://nodejs.org/api/tls.html#tls_tls_ssl.
If I run the same code, without providing options to https.createServer
it does not crush. However when trying to reach https://localhost the browser answers with ERR_SSL_VERSION_OR_CIPHER_MISMATCH
(chrome browser)
With curl
curl https://localhost
curl: (35) Unknown SSL protocol error in connection to localhost:-9824