How to reduce time it takes for API route to respond
Answered
Asian black bear posted this in #help-forum
Asian black bearOP
After working on an app and successfully tested it locally I was happy to push and deploy it to production. But in production I am getting an error trying to verify a registered user account. The error:
After doing some searches, I found out that my app
Can setting up
better yet has anyone ran into similar issues, and how were they able to resolve it?
504: GATEWAY_TIMEOUT
Code: FUNCTION_INVOCATION_TIMEOUT
ID: iad1::788vh-1701290467696-3263f67644da
POST https://app.com/api/email/emailLogic 504 (Gateway Timeout)
fetchData @ register-cb8e36d88ec90902.js:1
(anonymous) @ register-cb8e36d88ec90902.js:1
Rj @ framework-467b11a89995b152.js:9
Ik @ framework-467b11a89995b152.js:9
(anonymous) @ framework-467b11a89995b152.js:9
Qk @ framework-467b11a89995b152.js:9
Fk @ framework-467b11a89995b152.js:9
jg @ framework-467b11a89995b152.js:9
(anonymous) @ framework-467b11a89995b152.js:9
11:50:18.767
After doing some searches, I found out that my app
deployed to Vercel
can only be processed for 10 seconds. My question is - how to reduce the amount of time API route takes to respond
. The app also uses Prisma's Accelerate
to help with connection pooling, but what baffles me is why it takes longer than 10 sec to redirect user back to the app from clicking a link in the email. Can setting up
Turbopack
help resolve this, can adding connection pooling such as this help:const prisma = new PrismaClient({
// Configure connection pooling options here
// For example:
// datasources: {
// db: {
// max: 20,
// idleTimeoutMillis: 10000,
// },
// },
}).$extends(withAccelerate());
better yet has anyone ran into similar issues, and how were they able to resolve it?
Answered by Arinji
well, you could host the api externally if you cant get it under the 10s mark.. i did have some time issues... optimizing it wouldnt work so i just put it on an express server
4 Replies
well, you could host the api externally if you cant get it under the 10s mark.. i did have some time issues... optimizing it wouldnt work so i just put it on an express server
Answer
but you should work on optimizing first, see if you hit external apis and if its possible to cache them etc
Asian black bearOP
Thank you @Arinji
No worries, mark an answer if you do find your issue resolved