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

237
Views
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
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!