Judy
Judy

Reputation: 434

Error: 502: {“errorMessage”: ” Task timed out after 10.01 seconds”} nextJS netlify

I have a website with the backend of Strapi CMS on Heroku, and NextJS frontend on Netlify. I don’t know why sometimes while navigating to other pages, the website gives this error of 502 {“errorMessage”:“2021-02-28T07:01:23.806Z 4234f202-e15d-4a25-84ce-79b9c82ac634 Task timed out after 10.01 seconds”}

I know, that this issue comes from limited execution time to 10s of function for serverless apps.

Is there any way to fix this??

Can I reduce the execution time of functions in nextJS??

Thanks in advance,

Judy

Upvotes: 2

Views: 1115

Answers (1)

Shahinoor Rahman
Shahinoor Rahman

Reputation: 11

I think I have gotten to the bottom of this for my web app.

I am using Strapi/Next.js for my app on Netlify as well.

My Next.js pages/index page was getting the issue, so I checked my functions and found that I was running API calls inside of getStaticProps for whatever reason. I switched this up to getServerSideProps, and this resolved my issue immediately.

*So I changed the below:

export async function getStaticProps() {   
  return {
    props: { ... }
  }
}

to this:

export async function getServerSideProps() {
  return {
    props: { ... }
  }
}

Upvotes: 1

Related Questions