Git Product home page Git Product logo

fastapi-react's Introduction

Developing a Single Page App with FastAPI and React

Want to learn how to build this?

Check out the post.

Want to use this project?

  1. Fork/Clone

  2. Run the server-side FastAPI app in one terminal window:

    $ cd backend
    $ python3.9 -m venv env
    $ source env/bin/activate
    (env)$ pip install -r requirements.txt
    (env)$ python main.py

    Navigate to http://localhost:8000

  3. Run the client-side React app in a different terminal window:

    $ cd frontend
    $ npm install
    $ npm run start

    Navigate to http://localhost:3000

fastapi-react's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastapi-react's Issues

How do you serve the staticly built React app?

Once you are ready to move to production, you'll need to have the backend and frontend running on the same domain (to take advantage of things like HTTP-Only cookies, for example).

You can build the static React app files like so:

cd frontend
npm run build

But now how do you actually serve these from your FastAPI backend?

In my application I tried doing something like this:

api = FastAPI(root_path="/api")

# Create all my backend routes using @api.get() and @api/post() ...

app = FastAPI()
app.mount("/api", api)
app.mount("/", StaticFiles(directory="frontend/build", html=True), name="static")

This sort of works. I am able to get to my root frontend index by going to http://localhost:5000, but when I try to navigate to any other route in my React app (as defined by react-router-dom) I just get a 404 Not Found from the backend.

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.