- jokes.py: Public joke listing, detail, and random endpoints - categories.py: Type and crowd listing endpoints - auth.py: Login endpoint with JWT token generation - admin.py: Full CRUD for jokes, types, crowds with JWT protection - Fix request body schemas to use Create DTOs instead of Response models Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
33 lines
764 B
Python
33 lines
764 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import API_TITLE, API_VERSION
|
|
from app.routers import jokes_router, categories_router, auth_router, admin_router
|
|
|
|
# Create FastAPI application
|
|
app = FastAPI(title=API_TITLE, version=API_VERSION)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Mount routers
|
|
app.include_router(jokes_router)
|
|
app.include_router(categories_router)
|
|
app.include_router(auth_router)
|
|
app.include_router(admin_router)
|
|
|
|
|
|
@app.get("/")
|
|
def root():
|
|
return {"message": "欢迎使用笑话大全 API"}
|
|
|
|
|
|
@app.get("/health")
|
|
def health_check():
|
|
return {"status": "healthy"} |