Add FastAPI backend and React frontend setup with initial routes and components
This commit is contained in:
@@ -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")
|
||||
@@ -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"}
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
# backend/app/routers/__init__.py
|
||||
@@ -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"}]
|
||||
@@ -0,0 +1,3 @@
|
||||
fastapi==0.100.0
|
||||
uvicorn==0.22.0
|
||||
pydantic==2.0.2
|
||||
Reference in New Issue
Block a user