Using Express & Postgres backend
Answered
Tibbs posted this in #help-forum
TibbsOP
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
If you like using the nextjs api routes... Use that.. if not then dont
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
Just google
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 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
TibbsOP
I have a hosted version which is using the live server and so far no issues testing the logging in, signing up etc?
@Arinji the only actual issues you would face are working on end to end typeafety between your backend and your frontend.. but thats it
TibbsOP
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
@Tibbs 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
What url will you be hosting your api on
TibbsOP
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
If you like using the nextjs api routes... Use that.. if not then dont
Answer
TibbsOP
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
TibbsOP
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
TibbsOP
import cors from "cors";
app.use(cors());
app.use(express.json());
app.use(cors());
app.use(express.json());
That's sufficient right?
Yep
If it works.. yes
TibbsOP
Ty
Original message was deleted
Boop