I have a React app with a Flask backend listening on port 5000 on
localhost (flask’s default). Can I add another backend using express to the same web app that also listens on port 5000? but I wanted to have multiple backends working from the same frontend.
To clarify, my use case is like this:
POSTrequest to her Flask, the data is saved to a local database.
Most online tutorials only have one backend, but I wanted to work with a more complex system. I was thinking of the following ideas –
fetch('flask/api/save'from React and
@app.route('flask/api/save')to Flask backend Save data to code> Save data to local database
fetch('express/api/doWork). Here we use the same port 5000 to connect to the updated local database. Send Flask from Express using
app.get('/express/api/doWork)and send the appropriate response.
Is this possible? Or is there a better way to achieve this communication?
I finally figured out the answer myself. It’s not possible for 2 servers to listen on the same port. The solution here would be to use Flask as a reverse proxy and redirect the client calls to the express server.
Reference – Multiple backend servers accessible from a Flask server
Answered By – addybist
Answer Checked By – Gilberto Lyons (Easybugfix Admin)