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

153
Vistas
Get the hostname inside getStaticProps

Is it possible to get the hostname inside getStaticProps?

export async function getStaticProps(context) {
  // get the hostname 
  const hostname = ?????
}
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

It's not possible to get the hostname inside getStaticProps as the props generated there are static and do not contain information on the request in any way. To get the hostname, you will have to use getServerSideProps or get the hostname on the client side in the page's component. Here is an example of getting the hostname in getServerSideProps:

export const getServerSideProps: GetServerSideProps<{ host: string; }> = async (context) => {
  return {
    props: { host: context.req.headers.host || null }
  };
};

Here is an example of getting the hostname on the client side component using Location:

function Home() {
  // window can be undefined when static generated, however it will be updated when the page is hydrated
  const hostname = typeof window !== 'undefined' ? window.location.hostname : '';
}

export default Home;
about 4 years ago · Santiago Trujillo Denunciar

0

create function :

export const hostname = "https://urldomain.com"

and import everywhere

import {hostname} from "./hostname";

export async function getStaticProps(context) {
 // get the hostname 
console.log(hostname)
}
about 4 years ago · Santiago Trujillo 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