我需要将所有 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');
});
Run Code Online (Sandbox Code Playgroud)
并且重定向不适用于静态文件。如果我改变顺序:
app.get(...);
app.use(...);
Run Code Online (Sandbox Code Playgroud)
然后我的静电不起作用。如何重定向此类请求?