I am currently using Next.js@latest with App Directory
My application is hosted on Vercel
I'm experiencing a 504 error from Vercel and I'm on the pro plan. My serverless functions are set to run for up to 5 minutes, but usually, they only take about 2-3 minutes to complete.
When checking the logs, I can see that the serverless function is returning a 200 status code and running correctly. However, when accessed through the browser or postman, it times out after approximately 1 minute and returns a 504 error.
Everything seems to work fine locally. What could be causing this issue?
app/api/generators/article/refine/route.ts
import { type NextRequest } from "next/server";
import { type GetArticle } from "@/types/types";
import GeneratorsAPI from "@/lib/GeneratorsApi/GeneratorsAPI";
export const maxDuration = 300;
export async function POST(request: NextRequest) {
const payload = (await request.json()) as GetArticle;
return await GeneratorsAPI.getInstance().getRefinedArticle(payload);
}
lib/GeneratorsAPI
async getRefinedArticle(payload: GetArticle) {
try {
this.validatePayloadWith(this.articleValidator, payload);
const response = await axios.post(this.REFINED, payload, {
headers: this.headers,
timeout: 300000,
});
const data = response as ArticleAPIReturnType;
return NextResponse.json({ data: data.data.data }, { status: 200 });
} catch (err) {
const error = handleError(err, "getRefinedArticle");
return NextResponse.json(
{ message: error.message },
{ status: error.errorCode },
);
}
}
This information is extracted from VERCEL LOGS for /refine route
Status Code: 200
Execution duration/limit: 1m 45.76s / 250s
function: /api/generators/article/refine
Environment: production