我正在尝试将我的 http 页面重定向到 https,我在 stackoverflow How to force SSL / https in Express.js中发现了一些讨论。但现在 http = express.createServer() 已被弃用。所以我试图做如下:
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");
});
你能告诉我为什么会出现这个错误吗?(ECONNREFUSED)我应该修改什么才能让它工作,http重定向到https?
问候,-M-