Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Heroku http到https转发问题_Node.js_Heroku_Https_Express - Fatal编程技术网

Node.js Heroku http到https转发问题

Node.js Heroku http到https转发问题,node.js,heroku,https,express,Node.js,Heroku,Https,Express,在Heroku托管的应用程序中使用Node/Express。我有一个从http到https的转发功能,它曾经工作过,但现在不再工作了 我已从我的应用程序中使用以下内容。配置('production'): app.configure('production', function() { return app.use(function(req, res, next) { if (req.header('x-forwarded-proto') !== 'https') { re

在Heroku托管的应用程序中使用Node/Express。我有一个从http到https的转发功能,它曾经工作过,但现在不再工作了

我已从我的
应用程序中使用以下内容。配置('production'
):

app.configure('production', function() {
return app.use(function(req, res, next) {
    if (req.header('x-forwarded-proto') !== 'https') {
        return res.redirect("https://" + (req.header('host')) + req.url);
    } else {
        return next();
    }
});
它成功了,我很满意,并开始实施Redis to go,而不是MemoryStorage,然后实施csrf中间件。这两个功能都在发挥作用,但现在我发现我可以通过
http://...
而在此之前,它会被捕获并自动转发到
https://...
和fr绿色挂锁

你知道在这期间会有什么变坏吗?

自我回答:

在csrf实施过程中,我对我的
app.configure
部分做了以下更改:

app.use(app.router);

我在csrf演示中读过这个用法。但我不知道是否有必要。当我评论这一行时,csrf中间件的功能似乎没有受到影响,Heroku重定向与以前一样工作。

不太确定app.router是如何干扰express.req的,但这是我对发生了什么的最好猜测。