Next.js Discord

Discord Forum

Using Express & Postgres backend

Answered
Tibbs posted this in #help-forum
Open in Discord
I am using an express server with postgres and used nextjs for the frontend, however I am wondering if there are setbacks to using it like this? I wanted extra control over the authentication on the backend which is why I chose to do it like this, but looking for tips that would make it smoother whilst building, I am not the greatest with API routes in Next js and currently my endpoints are mostly on one with multiple parameters on there, I have done this before with Vite but not with Next, any help would be greatly appreciated
Answered by Arinji
Yup, that's normal..at the end of the day it's a preference thing.

If you like using the nextjs api routes... Use that.. if not then dont
View full answer

24 Replies

its a good idea to make your own backend instead of using nextjs
the only actual issues you would face are working on end to end typeafety between your backend and your frontend.. but thats it
also cors handling is another issue you will face. Basically your api will be on a different domain, maybe api.example.com whereas your frontend is at example.com if you make a client side request to your backend.. the browser wont allow it. But its easily fixable.

Just google express cors fix
@Arinji the only actual issues you would face are working on end to end typeafety between your backend and your frontend.. but thats it
I've gotten some mixed messages from people about it, some say to take away the use of api routes in my next js app and use fetch directly, as currently it goes frontend -> api route -> backend
Others like you have said its a good way to do things using my own backend but im not following the cors issues thats brought up
Through supabase and render so a separate one
@Tibbs I've gotten some mixed messages from people about it, some say to take away the use of api routes in my next js app and use fetch directly, as currently it goes frontend -> api route -> backend
Yup, that's normal..at the end of the day it's a preference thing.

If you like using the nextjs api routes... Use that.. if not then dont
Answer
as long as the app is working, im good right? I can work on optimising it after its got a nicer UI?
@Tibbs Through supabase and render so a separate one
That's the thing, your website will make client side requests to a different domain, that gets blocked by the browser
That's called a cors issue
So far its been ok, I've added the simple cors for json in the backend
Yup
It's nothing hard.. just stuff you need to keep note of
import cors from "cors";
app.use(cors());
app.use(express.json());
That's sufficient right?
Yep
If it works.. yes
Ty
@Tibbs Ty
Np, mark a solution
Original message was deleted
Boop