Files
xiaoxia-saas/apps/api/main.py
T
Xiaoxia AI 37836b2755 feat(app): add FastAPI main application and configuration
- Create main.py with CORS and GZip middleware
- Add Settings class with all configuration options
- Support .env file for environment variables
- Add health check and root endpoints
- Create comprehensive README with quick start guide
- Add .env.example template
- Include API usage examples and troubleshooting

Phase 4 Task 30/68 completed
2026-06-17 07:42:22 +08:00

62 lines
1.3 KiB
Python

"""
FastAPI 主应用
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from apps.api.app.api.routes import api_router
# 创建 FastAPI 应用
app = FastAPI(
title="小虾 SaaS API",
description="自动化剪辑 SaaS 平台 API",
version="1.0.0",
docs_url="/docs",
redoc_url="/redoc",
)
# CORS 中间件
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:3000",
"http://localhost:5173",
"https://yourdomain.com",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Gzip 压缩
app.add_middleware(GZipMiddleware, minimum_size=1000)
# 注册路由
app.include_router(api_router)
@app.get("/")
async def root():
"""健康检查"""
return {
"service": "小虾 SaaS API",
"status": "running",
"version": "1.0.0",
}
@app.get("/health")
async def health_check():
"""健康检查接口"""
return {
"status": "healthy",
"database": "ok", # TODO: 实际检查数据库连接
"redis": "ok", # TODO: 实际检查 Redis 连接
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)