【问题标题】:Express request object not correctly reporting https [duplicate]Express 请求对象未正确报告 https [重复]
【发布时间】:2017-06-23 14:21:26
【问题描述】:

我正在尝试将我网站的用户自动重定向到 https,但为了做到这一点,我需要知道他们是否已经通过 https 访问,否则我会进入无限重定向循环。

通过搜索,我尝试查看这些值

console.log('!!!!!!!!!ROUTING TO REDUX!!!!!!!!', request.secure, request.protocol, request.get('X-Forwarded-Protocol'));

但我看到这个被记录了

2017-06-23T07:20:10.996750+00:00 app[web.1]: !!!!!!!!!路由到 REDUX !!!!!!!!! false http 未定义

2017-06-23T07:20:11.028280+00:00 heroku[路由器]: at=info method=GET path="/" host=my-library-io.herokuapp.com request_id=3fc84fae-02bd-443a -8265-c45def605ba1 fwd="64.134.226.42" dyno=web.1 connect=0ms service=33ms status=200 bytes=2309 protocol=https

即使查看 https。

网站在这里https://mylibrary.io/ 原始Heroku url在这里https://my-library-io.herokuapp.com/

两个 URL 都已加载,并在我的浏览器中显示为安全,但通过上面的第二个条目,它们似乎也都以 https 登录;但是我无法查看请求对象中的任何内容来推测我正在通过 https 查看。

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    使用request.get('X-Forwarded-Proto'),而不是X-Forwarded-Protocol。如您所见,它被 npm 包heroku-ssl-redirect 使用。这个 de-facto 标准 HTTP 标头也是 documented on Wikipedia

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多