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

238
Vistas
next js how to get server url in getServerSideProps to fetch data from current api server

Obviously, this code always returns 404, because of fetch path 'api/registration/' + username, it doesn't work properly with related path .I don't see solution anywhere. Everybody just hardcode link like http://localhost:3000/api/registration/something but why should I hardcode it ? Is there any civilized way to fetch data from api of current server, where actually getServerSideProps was called? (that wouldn't work but anyway window.location.host+"/api/registration/something")

import axios from 'axios';
import { UserData } from '../src/common/types/user-types/UserData';

export default function UsernamePage(props) {
  console.log('Got props', props);
  return <div>Username Page</div>;
}

export async function getServerSideProps({ params: { username }, ...rest }) {
  console.log(rest);
  try {
    const { data } = await axios.get<UserData>('api/registration/' + username);
    return { props: { ...data } };
  } catch (e) {
    return { notFound: true };
  }
}
about 4 years ago · Santiago Trujillo
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