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

160
Views
Obtenga el nombre de host dentro de getStaticProps

¿Es posible obtener el nombre de host dentro getStaticProps ?

 export async function getStaticProps(context) { // get the hostname const hostname = ????? }
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

No es posible obtener el nombre de host dentro de getStaticProps ya que los accesorios generados allí son estáticos y no contienen información sobre la solicitud de ninguna manera. Para obtener el nombre de host, deberá usar getServerSideProps u obtener el nombre de host en el lado del cliente en el componente de la página. Aquí hay un ejemplo de cómo obtener el nombre de host en getServerSideProps :

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

Aquí hay un ejemplo de cómo obtener el nombre de host en el componente del lado del cliente usando 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 Report

0

crear función:

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

e importar en todas partes

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