我正在尝试将我的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 -