Should I Serve a React Build with Django or Use a Node.js Server if I am using Websockets with Django Channels?
I have a React application that I need to deploy, and I am considering two options for serving the production build:
1. Serving the React build directly with Django (e.g., using WhiteNoise or serving it as static files).
2. Using a Node.js server (such as Express) to serve the React build separately.
I am having a websocket server in django channels using asgi. But I have build a react app in using the react. As the SSR is better in performance I was wondering if whether I can server my react build with django or not.
Which approach is generally recommended, and what are the pros and cons of each?
If you have server-side components then absolutely you will need to a node.js server (which will do the rendering of react server-side components).
The case where you can use static files serving using Whitenoise or nginx, apache.. or something similar is when you have only one bundle file (or many) of your react app that was built and generated once every new deployment (each version) and in this case your react app is only client-side rendering.
The most important thing in your case is to have a single point of enterance, like you can direct all requests to django server and the django server will communicate with node.js server, or similarly, you can have nginx server which redirects some prefixes to the node.js server.