-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify backend/frontend/API code? #4
Comments
So there are two different things here:
That said, the API as it currently exists is pretty messy, and replacing it from scratch with a better graphql interface seems good. |
I feel strongly enough about this that I'll try to argue otherwise. Sorry for the long rant :) Some context:
Anyway, my points:
Here's what I have in mind:
I'll also note that even if we don't agree on this, it's important to keep all the code in the same codebase so that we don't have to think "do I need this function in Next.js or for my backend cron job? should I copy-paste?" (which really complicates things); since Next.js is smart with its bundling, there's no problem of pulling all the backend code into Next.js server, it still won't burden the frontend bundle, and it won't hurt the potential reuse of the same code for a different backend node process. |
To be fair, another benefit is that it allows to run the frontend code without running the database. Which might be useful for small-time contributors. But, extrapolating from the previous trends (and my own experience), contributors don't show up and add much value that often anyway. |
That makes sense. As you mentioned I was a bit paranoid about lock-in, but you mentioning
changes my mind because I'm mostly willing to trust your judgment here. One last issue would be that with the code as currently structured, it's relatively easy for others to re-use it, whereas that might be a bit more difficult if we start using the nextjs api layer. But that's easily solvable by having better documentation/examples in a different folder. |
Cool. I'll push |
Done by #8. |
Since
getStaticProps
andgetServerSideProps
code (and everything downstream of those) is not embedded in the frontend bundle, querying the DB directly from those is actually fine and recommended (see e.g. https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props)Unless I’m missing something, this means it’d be fine to unify all the code (frontend, backend and api) in a single Next.js app.
Secrets e.g. Postgres URL can be stored in env too (only the ones with
NEXT_PUBLIC_
prefix are passed to the frontend, see https://nextjs.org/docs/basic-features/environment-variables).If I understand correctly, the backend includes some kind of scheduler for updating the DB? (I haven't looked into the details yet). That can be handled with an API route and something like https://vercel.com/docs/concepts/solutions/cron-jobs (if we decide to use Vercel, see the next issue).
The text was updated successfully, but these errors were encountered: