Next.js Discord

Discord Forum

Why don't next 13 API routes work in deployment

Unanswered
British Shorthair posted this in #help-forum
Open in Discord
British ShorthairOP
Hi everyone, a couple of days ago I tried to build my own API using Prisma in Next 13 with the new Route Handlers however I encountered a problem when I deployed my application. I read the docs and it said that you should extract the API logic into the server components and the client is safe, and the API routes aren't preferred in that case, that's why when I deployed my app to vercel it didn't work at all. The thing is that I want to create my own API and how can I achieve that. Should I use another library like Express.js or the old api routes pages/api/..., or is it better to just retrieve the data from a "use server" file like so export async function getData()

15 Replies

British ShorthairOP
yeah i know but I like to seperate my logic into another folder named actions and if I don't use use server an error occurres telling me that server side logic cannot be excecuted in the browser
@British Shorthair yeah i know but I like to seperate my logic into another folder named `actions` and if I don't use `use server` an error occurres telling me that server side logic cannot be excecuted in the browser
No. "use server" marks serverside logic that can be executed on the browser, it is not necessary for data fetching. Just use a normal async getData inside a server component, no fetching from the browser
@British Shorthair Yes
Sokoke
Try doing
Actions/
—client/
——index.ts
—server/
——index.ts
That’s how I avoided those error
British ShorthairOP
When I use "use server" it works fine for both the client and the server
can you give me an example on how / why should I seperate the logic
Sokoke
Cause some server side logic might require native node api’s
Leading to module res errors
British ShorthairOP
ok thanks, btw @Sokoke can you help me with something middleware related, as I can't understand a single thing
Sokoke
I started next like a week ago XD.
Still trying to completely understand some fundemtal concepts before I tackle other stuff lol
British ShorthairOP
no worries😃