20 lines
457 B
Python
20 lines
457 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from core.config import settings
|
|
from routes import example
|
|
|
|
app = FastAPI(title=settings.app_name)
|
|
|
|
# 允许所有域名跨域访问
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # ⚠️ 生产环境建议指定域名
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 注册路由模块
|
|
app.include_router(example.router, prefix="/api")
|