第一次提交

This commit is contained in:
2025-06-27 20:20:51 +08:00
commit 33f86752de
153 changed files with 6743 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
# 可放项目配置,例如环境变量、数据库连接信息
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
app_name: str = "My FastAPI App"
host: str = '0.0.0.0'
debug: bool = True
settings = Settings()

19
test/server/main.py Normal file
View File

@@ -0,0 +1,19 @@
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")

View File

@@ -0,0 +1,8 @@
from fastapi import APIRouter, Response
router = APIRouter()
@router.get("/hello")
def hello(response: Response):
response.set_cookie(key="cookie1", value="value1")
return {"message": "Hello, FastAPI with CORS!"}