Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

523
Views
Cómo obtener la URL completa del navegador en el próximo js, getServerSideProps

Ahora, estoy en http://localhost:3000/ , pero en prod estaré en una URL diferente, por ejemplo, http://example.com/ , ¿cómo puedo obtener la URL completa del navegador en getServerSideProps? Tengo que obtener http://localhost:3000/ o http://example.com/ , si la cadena no contiene el puerto, estará bien

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Y en la respuesta adicional que usas en este mi caso:

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

Esta URL te da, por ejemplo, http://localhost:3000 ¡disfrútalo!

about 4 years ago · Juan Pablo Isaza Report

0

'next/router' también proporciona un par de métodos que puede usar. Por ejemplo:

 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); }

Si tiene el host, puede verificar si contiene localhost. Entonces sabes que estás en tu entorno local.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!