I\'ve been googling and looking here at stackoverflow, but I can\'t find an answer I like ;-)
I have a NodeJS server that runs over HTTPS and port 3001. Now I\'d lik
I know its an old question but just putting it as a reference for someone else. The easiest way that I found was to use the https://github.com/mscdex/httpolyglot module. Seems to do what it says quite reliably
var httpolyglot = require('httpolyglot');
var server = httpolyglot.createServer(options,function(req,res) {
if (!req.socket.encrypted) {
// Redirect to https
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
} else {
// The express app or any other compatible app
app.apply(app,arguments);
}
});
// Some port
server.listen(11000);