How to know if a request is http or https in node.js

前端 未结 9 1252
别跟我提以往
别跟我提以往 2020-12-08 04:11

I am using nodejs and expressjs. I wonder if there is something like request.headers.protocol in the clientRequest object. I would like to build the baseUrl for

9条回答
  •  星月不相逢
    2020-12-08 04:17

    If you want to know whether request is http or https then use this in your code:

    req.headers.referer.split(':')[0];
    

    This will return whether req is http or https.

提交回复
热议问题