Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

531
Vistas
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

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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!

about 4 years ago · Juan Pablo Isaza Denunciar

0

'next/router' provide a couple of methods too, which you can use. For example:

import { useRouter } from 'next/router';

const RouterObject = () => {
  const { asPath, pathname, req, query, res } = useRouter();
  console.log(asPath);
  console.log(pathname); 
  console.log('host: ', req.headers.host);
}

If you have the host you can check if contains localhost. Then you know you are in your local environment.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda