Add FastAPI backend and React frontend setup with initial routes and components

This commit is contained in:
2024-12-24 19:55:36 +01:00
parent 872fb54ecc
commit 42a447f12e
10 changed files with 114 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
from fastapi import Header, HTTPException
async def get_token_header(x_token: str = Header()):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
+21
View File
@@ -0,0 +1,21 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .routers import example_router
app = FastAPI()
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"], # Vite's default port
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(example_router.router)
@app.get("/")
async def root():
return {"message": "Welcome to FastAPI"}
+2
View File
@@ -0,0 +1,2 @@
# backend/app/routers/__init__.py
+11
View File
@@ -0,0 +1,11 @@
from fastapi import APIRouter
router = APIRouter(
prefix="/api",
tags=["example"],
responses={404: {"description": "Not found"}},
)
@router.get("/items")
async def read_items():
return [{"name": "Item 1"}, {"name": "Item 2"}]
+3
View File
@@ -0,0 +1,3 @@
fastapi==0.100.0
uvicorn==0.22.0
pydantic==2.0.2