Problem:
Application is using Page router and there are SSR API requests runs on each deploy and after each caching expires cycle
The API requests takes sometimes more than 30 seconds to fetch all the data
Vercel infrastructure Serverless Functions Execution Duration is 15 seconds although the plan is PRO!
So sometimes getting 504 error:
Solution:
Setting maxDuration of Serverless Functions Execution Duration by:
- Create vercel.json file in the root folder of the project
- If you use page router use pages/**/* pattern
- Add code below to vercel.json file:
{
"functions": {
"pages/**/*": {
"maxDuration": 300
}
}
}
Now the “Serverless Functions Execution Duration” will be 300 seconds (5 minutes)
Note that:
“Hobby” plan has max 10 seconds,
“Pro” plan has max up to 300 seconds and
“Enterprise” plan can be up to 900 seconds
(these numbers posted in this blog on 12 December 2023, and maybe changed in the future)