The best way to connect Next.js CSR React app, Django and PostgreSQL

Viewed 3029

My question concerns programming a full-stack app.

On the frontend, I have a Next.js React app. I want to render it on the client-side and probably use SWR. On the backend, I have a Django app with a PostgreSQL database.

I have seen two approaches to make all of these work together.

The first one is to use Django to serve Next.js React app with django-webpack-loader and then to load React app within Django template.

The second one is to build two separate apps - frontend (Next.js) and backend (Django + PostgreSQL) and deploying them on two servers (e.g. Docker container). I have read this article and it makes me lean towards the second option. However, it is a pretty old solution and maybe some things have changed since then.

What is the most optimal solution when it comes to connecting Next.js React Client-side rendered, Django and PostgreSQL?

1 Answers

Opinions may differ, but based on reading and personal experience, I consider using separate Next.js and Django apps to be preferable. This (1) helps with separation of concerns, (2) helps avoid making Django or Next.js do anything that their designers did not anticipate, and (3) is simple with Docker.

Here's an example project that uses docker-compose to manage services including a Next.js frontend, Django backend, and Postgres database: https://github.com/ModularHistory/modularhistory

Related