我读过很多同名的帖子。我已经尝试了给出的建议,没有奏效
我想在生产中自动重定向 - 如果它不安全。这是一个 angular2 应用程序,服务器 api。
这是快速应用程序中的第一个中间件.js
// HTTPS
app.use (function (req, res, next) {
if ( req.secure || req.headers.host === 'localhost:3002' ) {
next();
} else {
res.redirect('https://' + req.headers.host + req.url);
}
});
我从FF得到的消息是这样的
The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
我没有禁用饼干。 而且我没有在角度中引用协议,所以我不知道为什么它会在重定向上犹豫不决。我在哪里可以看?我可以尝试什么?
显然 Express 封装了一些标头解析,我需要包含
app.enable('trust proxy'(;
优秀的文章 - https://www.tonyerwin.com/2014/09/redirecting-http-to-https-with-nodejs.html