添加了完整的前后端开发环境配置,包括: - 创建 .gitignore 文件忽略本地生成目录和环境文件 - 添加详细的 README.md 开发指南文档 - 配置 backend 目录结构和 FastAPI 应用基础框架 - 实现应用配置管理、健康检查和状态接口 - 设置 uv 依赖管理和虚拟环境配置 - 完成 CORS 中间件配置支持前端开发联调
36 lines
951 B
Python
36 lines
951 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import get_settings
|
|
from app.schemas import HealthResponse, ServiceStatusResponse
|
|
|
|
settings = get_settings()
|
|
|
|
app = FastAPI(
|
|
title=settings.name,
|
|
version=settings.version,
|
|
description="AI 笔记软件的本地 FastAPI 服务壳子。",
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://127.0.0.1:5173", "http://localhost:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/health", response_model=HealthResponse, tags=["System"])
|
|
async def health() -> HealthResponse:
|
|
return HealthResponse()
|
|
|
|
|
|
@app.get("/api/status", response_model=ServiceStatusResponse, tags=["System"])
|
|
async def service_status() -> ServiceStatusResponse:
|
|
return ServiceStatusResponse(
|
|
name=settings.name,
|
|
version=settings.version,
|
|
environment=settings.environment,
|
|
)
|