Monday, 3 April 2017

Redirect http to https with Node.js

I have a Node.js server, with an active SSL certificate on the domain. I have read some replies on this website about this, yet even when I relate to such already-solved questions, I get an error.

var express = require('express');
var https = require('https');
var http = require('http');
var path = require('path');
var fs = require('fs');
var mysql = require('mysql');

var queue = {};
var qc = {};

var app = express();

var options = {
    key: fs.readFileSync('sslcert/domain-name.key', 'utf8'),
    cert: fs.readFileSync('sslcert/domain-name.csr', 'utf8')
};

var httpServer = http.createServer(app);
var httpsServer = https.createServer(options, app);

/* various stuff to display my website */

httpServer.listen(process.env.PORT);
httpsServer.listen(process.env.PORT);

I get the following error in my console.

_tls_common.js:67
      c.context.setCert(options.cert);
                ^

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    at Error (native)
    at Object.createSecureContext (_tls_common.js:67:17)
    at Server (_tls_wrap.js:754:25)
    at new Server (https.js:17:14)
    at Object.exports.createServer (https.js:37:10)
    at Object.<anonymous> (/srv/data/web/vhosts/default/server.js:35:25)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

Thank you in advance for your answer!

Noël.



via Noël Nadal

No comments:

Post a Comment