Prisma throws a 504 error, but only when the next js project is deployed to vercel.
Unanswered
kubas posted this in #help-forum
kubasOP
Hi! I have a api routes where I want prisma to get me something from the database. This is what they look like:
or
When I send a request to these routes, I get error 504, how to fix it?
import { PrismaClient } from "@prisma/client";
import { NextResponse } from "next/server";
const prisma = new PrismaClient();
export async function GET() {
const authors = await prisma.author.findMany();
return NextResponse.json(authors);
}or
import { NextRequest, NextResponse } from "next/server";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export async function GET(req: NextRequest) {
const authorId = req.nextUrl.searchParams.get("authorId");
if (!authorId)
return NextResponse.json({ message: "Missing authorId" }, { status: 400 });
const author = await prisma.author.findUnique({
where: {
id: authorId as string,
},
});
if (author !== null) {
return NextResponse.json(author);
} else {
return NextResponse.json({}, { status: 404 });
}
}When I send a request to these routes, I get error 504, how to fix it?
10 Replies
kubasOP
I am using mongodb
i see this type of issues these day. basically Vercel recommends Vercel Postgres or KV for database as Vercel platform uses serverless environments such as AWS Lambda and Cloudflare Worker, where db connection pooling does not work well, causing 504 timeout error.
https://vercel.com/guides/using-databases-with-vercel
https://vercel.com/guides/using-databases-with-vercel
@tafutada777 i see this type of issues these day. basically Vercel recommends Vercel Postgres or KV for database as Vercel platform uses serverless environments such as AWS Lambda and Cloudflare Worker, where db connection pooling does not work well, causing 504 timeout error.
https://vercel.com/guides/using-databases-with-vercel
kubasOP
So if I change the hosting, everything should work?
i host a Next.js on GCP k8s, connecting to MongoDB. it works fine so far.
@tafutada777 i host a Next.js on GCP k8s, connecting to MongoDB. it works fine so far.
kubasOP
do you know any other hosts? Because when registering for gcp I have to provide my card.
Heroku used to be free, but nothing comes for fee, especially DB consumes CPU and memory a lot, so it is a bit expensive. if it's a toy project, Azure has a free $200 credit with hard limit on credit card charge.
@tafutada777 Heroku used to be free, but nothing comes for fee, especially DB consumes CPU and memory a lot, so it is a bit expensive. if it's a toy project, Azure has a free $200 credit with hard limit on credit card charge.
kubasOP
now i have another question, what hosting would you recommend (paid)? This is my first project for a client and I would have to get some hosting and a domain.
because I was using vercel to test apps on deployment
as u may know, AWS is the most popular cloud, personally im graviating towards Azure because of OpenAI API, gpt stuff.
there are so many documents, blogs, developers around AWS, so you would get reply soon if u hit issues like this. it's big advantage aside from costs.