1

My page import some module: import module In getServerSideProps I get query and call api, then return response.

export async function getServerSideProps(context) {
  try {
    var startTime = Date.now();
    const query = context.query;
    const url = `myurl with query`;
    const searchResulf = await axios.get(url);
    var endTime = Date.now();
    console.log(`Took ${endTime - startTime} milliseconds`);
    return {
      props: {
        searchResulf: searchResulf.data,
      },
    };
  } catch (error) { 
    console.error("error"); 
    return {
      props: {
      searchResulf: null,
    },
  }; 
}};

In localhost everything is fine, never more than 2s waiting for api.

Took 939 milliseconds
Took 415 milliseconds
Took 840 milliseconds

In brower, never more than 5s for file HTML: enter image description here

But when deploying on netlify (and vercel) this page is broken, other sites work properly. The function log get nothing, just "Error: Task timed out after 10.02 seconds".

I'm new to Nextjs, this is my first project, I'm stuck here for 2 days because of this error.

  • Is the URL internal (to an internal Next.js API route) or an external API endpoint? – juliomalves Jun 13 '22 at 18:10
  • It's API route. I've a console.log under getServerSideProps() before even the try-catch. But funcion log nothing, maybe getServerSideProps not working yet. – Nguyễn Tuấn Kiệt Jun 17 '22 at 03:38
  • 1
    You shouldn't call internal API routes inside `getServerSideProps`, instead use the API logic directly. See [Internal API fetch with getServerSideProps? (Next.js)](https://stackoverflow.com/questions/65752932/internal-api-fetch-with-getserversideprops-next-js). – juliomalves Jun 17 '22 at 08:52

0 Answers0