Initial commit: Audio Dashboard Management System
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from database import engine, Base
|
||||
from routes import brands_router, models_router
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
# Create database tables (only if tables don't exist)
|
||||
try:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not create tables: {e}")
|
||||
print("Continuing without table creation...")
|
||||
|
||||
# Create FastAPI app
|
||||
app = FastAPI(
|
||||
title=os.getenv("APP_NAME", "Audio Dashboard API"),
|
||||
description="耳机品牌与型号管理平台后端 API",
|
||||
version="1.0.0"
|
||||
)
|
||||
|
||||
# Configure CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # 生产环境应该限制具体域名
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Include routers
|
||||
app.include_router(brands_router)
|
||||
app.include_router(models_router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def root():
|
||||
"""根路径"""
|
||||
return {
|
||||
"message": "欢迎使用 Audio Dashboard API",
|
||||
"docs": "/docs",
|
||||
"redoc": "/redoc"
|
||||
}
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health_check():
|
||||
"""健康检查"""
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host="0.0.0.0",
|
||||
port=8002,
|
||||
reload=False
|
||||
)
|
||||
Reference in New Issue
Block a user