Where to run FastAPI backend, and how to connect to it with JavaScript running on a React App in a static site?

I have a backend written in Python with FastAPI - which handles some database stuff - but am not sure where I’m supposed to run it.

I also have a ReactJS frontend, which sends a request to my backend when a certain function is called.

I’m not sure how to link the two. During development, to link them, I simply ran the backend on, and added a proxy of “localhost:5000” to my ReactJS package.json file.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 26, 2024
Accepted Answer

Hi there,

What you could do here is to use the DigitalOcean App Platform:

First you will start by deploying your React app as a static component as described in this post here:

After that, you can deploy your FastAPI as a web service component to the same app. That way you will have two separate components both under the same app:

For your backend app, you could set its route to something like /api and then you will be able to call that /api route from your React frontend service.

If your backend service needs a database, you could also add a database service to that app as described here:

Here is a quick video that shows how you could do that but with a Laravel backend instead:

Hope that this helps!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel