0

//This is my index code "/" which I think is the error, which is the fetch with the localhost, what happens is that I do not know how to change that localhost:3000 when deploying to Vercel. Does anyone have a solution?

export async function getServerSideProps(ctx) {
  const res = await fetch("http://localhost:3000/api/tasks");

  const tasks = await res.json();

  console.log(tasks);

  return {
    props: {
      tasks,
    },
  };
Michael M.
  • 10,486
  • 9
  • 18
  • 34
  • You can use relative url like "/api/tasks". This should resolve correctly to [your_website_host]/api/tasks. – Kayasit R. Oct 12 '22 at 05:57
  • 1
    You shouldn't make calls to your own API routes on `getServerSideProps`, `getStaticProps` or `getStaticPaths`. More about this [on the docs](https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props#getserversideprops-or-api-routes). – ivanatias Oct 14 '22 at 03:46

0 Answers0