0

getInitialProps is the function of nextsj https://nextjs.org/docs/api-reference/data-fetching/get-initial-props .

Page.getInitialProps = async (ctx) => {
 const req= ctx.req;
}

I want to know about protocol by this req object.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
user14384267
  • 163
  • 6
  • Does this answer your question: [How to know if a request is http or https in node.js](https://stackoverflow.com/questions/10348906/how-to-know-if-a-request-is-http-or-https-in-node-js)? – juliomalves Sep 27 '22 at 18:08
  • nope, not getting anything in nextjs. – user14384267 Sep 29 '22 at 09:44
  • `req.headers.referer` should contain the absolute address of page that made request thus you can check it against `https` `req.headers.referer.includes("https://")` – Adrian Bienias Sep 29 '22 at 20:42
  • ^ it won't work properly when the request to your page comes from an external website (referer can be a different resource) – Adrian Bienias Sep 29 '22 at 20:54

0 Answers0