admin管理员组文章数量:1335544
I have an API endpoint on a NextJS project that needs longer than 60s to run. I'm on a pro Vercel plan but for some reason cannot get the timeout limit to increase.
At the endpoint itself I've tried
export const maxDuration = 300
export const dynamic = 'force-dynamic'
which doesn't seem to do anything, I also tried adding a vercel.json
file at the top level (above /src
) like so:
{
"functions": {
"pages/api/**": {
"memory": 3008,
"maxDuration": 300
},
}
}
Which again isn't working. I've bed through the documentation (mostly here) and also a handful of threads (one example), none of which have helped.
I'm running NextJs version 13.5.6
, am definitely on a pro plan, and Node v18, what am I doing wrong? Am really unsure of what else to try.
I have an API endpoint on a NextJS project that needs longer than 60s to run. I'm on a pro Vercel plan but for some reason cannot get the timeout limit to increase.
At the endpoint itself I've tried
export const maxDuration = 300
export const dynamic = 'force-dynamic'
which doesn't seem to do anything, I also tried adding a vercel.json
file at the top level (above /src
) like so:
{
"functions": {
"pages/api/**": {
"memory": 3008,
"maxDuration": 300
},
}
}
Which again isn't working. I've bed through the documentation (mostly here) and also a handful of threads (one example), none of which have helped.
I'm running NextJs version 13.5.6
, am definitely on a pro plan, and Node v18, what am I doing wrong? Am really unsure of what else to try.
1 Answer
Reset to default 6What you've done seems to be a mix of the Pages Router way the and the App Router way of doing it. Try to do it like in this example below:
With Pages Router (/pages/api/my-function/handler.ts
):
export const config = {
maxDuration: 5, // 5 seconds
};
export default function handler(
request: NextApiRequest,
response: NextApiResponse,
) {
response.status(200).json({});
}
With App Router (/app/api/my-function/route.ts
):
export const maxDuration = 5; // 5 seconds
export const dynamic = 'force-dynamic';
export function GET(request: Request) {
return new Response('{}', { status: 200 });
}
If you want to override the maximum duration of a function for your whole project when using Vercel, you can do it in vercel.json
(I think this is only valid for the App Router):
{
"functions": {
"app/api/**/*": {
"maxDuration": 5
}
}
}
You can read more about all this on the official docs.
本文标签: javascriptHow to increase timeout limit on Vercel Serverless functionsStack Overflow
版权声明:本文标题:javascript - How to increase timeout limit on Vercel Serverless functions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742396407a2467011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论