In express.js req.protocol is not picking up “https” for my secure link. It always pics “http”

老子叫甜甜 提交于 2021-02-19 01:38:05

问题


req.protocol is not picking up "https" for my secure link. It always pics "http" . For creating my baseURL am using this. any solutions please?


回答1:


That's happening most probably because there is a proxy in between. In my case I am using Heroku.

If that's the case, you need to add app.enable('trust proxy'); to your express app.

Without enabling that, req.protocol returned http. After that change I got https.

You can also use req.secure to get true or false depending on if your app is secured by https or not.



来源:https://stackoverflow.com/questions/40459511/in-express-js-req-protocol-is-not-picking-up-https-for-my-secure-link-it-alwa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!