I am trying to redirect my http page to https, I found some discussion already there in stackoverflow How to force SSL / https in Express.js. But now http = express.createServer() has become deprecated. So I was trying to do as below:
var http = require("http")
, https = require("https");
var app = express();
/* If I use below it gives ECONNREFUSED error */
http.get('*', function(req, res) {
var path = req.headers.host;
var pos = path.indexOf(':');
res.redirect('https://' + path.substr(0, pos) + ':' + String(app.get('port')));
});
app.get('/', function(req, res) {
//Something
});
https.createServer(options, app).listen(8000, function(){
console.log("In Https");
});
http.createServer(app).listen(9000, function() {
console.log("In http");
});
Can you please let me know why this error comes here? (ECONNREFUSED) What I should modify to get it worked, http redirect to https?
Regards, -M-