54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
# 最简单的启动方式
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import uvicorn
|
|
|
|
app = FastAPI(
|
|
title="云盘应用 API",
|
|
description="现代化的云存储Web应用后端API",
|
|
version="1.0.0",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc"
|
|
)
|
|
|
|
# CORS中间件
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"message": "云盘应用 API",
|
|
"version": "1.0.0",
|
|
"docs": "/docs",
|
|
"health": "/health"
|
|
}
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {
|
|
"status": "healthy",
|
|
"message": "服务运行正常"
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 启动云盘后端服务...")
|
|
print("📍 服务地址: http://localhost:8000")
|
|
print("📚 API文档: http://localhost:8000/docs")
|
|
print("❤️ 健康检查: http://localhost:8000/health")
|
|
print("⏹️ 按 Ctrl+C 停止服务")
|
|
print("=" * 50)
|
|
|
|
uvicorn.run(
|
|
app,
|
|
host="0.0.0.0",
|
|
port=8000,
|
|
reload=False
|
|
) |