我需要将所有http请求重定向到https,包括对静态文件的请求。重定向nodejs向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(...);
然后我的静态不工作。如何重定向这些请求?
非常感谢。奇迹般有效。 –