【发布时间】:2017-01-24 13:14:19
【问题描述】:
我需要将所有 http 请求重定向到 https,包括对静态文件的请求。
我的代码:
app.use(express.static(__dirname + '/public'));
app.get('*', function(req, res) {
if (!req.secure){
return res.redirect('https://' + config.domain + ":" + config.httpsPort + req.originalUrl);
}
res.sendFile(__dirname + '/public/index.html');
});
并且重定向不适用于静态文件。如果我改变顺序:
app.get(...);
app.use(...);
然后我的静态不工作。如何重定向此类请求?
【问题讨论】:
标签: javascript node.js redirect express https