diff --git a/README.md b/README.md index 30f7ebf..bacead6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Flask + React Example +# FastAPI + React Example -Basic example with a Flask API and a React frontend (Vite). +Basic example with a FastAPI backend and a React frontend (Vite). ## Publish to CitadelHosts.com @@ -9,9 +9,9 @@ Basic example with a Flask API and a React frontend (Vite). ``` podman login registry.citadelhosts.com podman build -t registry.citadelhosts.com/react-frontend:latest frontend -podman build -t registry.citadelhosts.com/flask-backend:latest backend +podman build -t registry.citadelhosts.com/fastapi-backend:latest backend podman image push registry.citadelhosts.com/react-frontend:latest -podman image push registry.citadelhosts.com/flask-backend:latest +podman image push registry.citadelhosts.com/fastapi-backend:latest ``` @@ -22,10 +22,10 @@ cd backend python -m venv .venv source .venv/bin/activate pip install -r requirements.txt -python app.py +uvicorn app:app --reload --port 5000 ``` -Flask will run on `http://localhost:5000`. +FastAPI will run on `http://localhost:5000`. ## Frontend @@ -35,4 +35,4 @@ npm install npm run dev ``` -Vite will run on `http://localhost:5173` and proxy `/api` to the Flask server. +Vite will run on `http://localhost:5173` and proxy `/api` to the FastAPI server. diff --git a/backend/Containerfile b/backend/Containerfile index af41b21..c8a0e14 100644 --- a/backend/Containerfile +++ b/backend/Containerfile @@ -9,4 +9,4 @@ COPY app.py ./ EXPOSE 5000 -CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"] +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000"] diff --git a/backend/app.py b/backend/app.py index 1abff21..654cfe9 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1,14 +1,17 @@ -from flask import Flask, jsonify -from flask_cors import CORS +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware -app = Flask(__name__) -CORS(app) +app = FastAPI() +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) @app.get("/hello") +@app.get("/api/hello") def hello(): - return jsonify(message="Hello from Flask") - - -if __name__ == "__main__": - app.run(debug=True) + return {"message": "Hello from FastAPI"} diff --git a/backend/requirements.txt b/backend/requirements.txt index ea39874..3af9cb3 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,3 +1,2 @@ -flask==3.0.0 -flask-cors==4.0.0 -gunicorn==21.2.0 +fastapi==0.111.0 +uvicorn[standard]==0.30.1 diff --git a/frontend/index.html b/frontend/index.html index 2be3594..297c006 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -3,7 +3,7 @@ - Flask + React Example + FastAPI + React Example
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index cdd8ef2..933c952 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -35,9 +35,9 @@ function App() { return (
-

Flask + React

+

FastAPI + React

- Frontend fetches data from a Flask API endpoint. + Frontend fetches data from a FastAPI endpoint.