Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get full browser url in next js, getServerSideProps

Now, i'm in http://localhost:3000/, but on prod i will be in a different url, for example http://example.com/, how can i get full browser url in getServerSideProps? I have to get http://localhost:3000/ or http://example.com/, if string will not contain port, it will be ok

like image 460
Николай Краснов Avatar asked Oct 23 '25 05:10

Николай Краснов


1 Answers

And in the additional answer you use in this my case :

export const getServerSideProps = async (
  context: GetServerSidePropsContext
) => {
  const { req } = context;
  let url = req.headers.referer;
  let arr = url.split('/');
  url = `${arr[0]}//${arr[2]}`;

This URL gives you for example http://localhost:3000 enjoy!

like image 110
Omid Moghadas Avatar answered Oct 24 '25 17:10

Omid Moghadas