问题
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