35 lines
905 B
Python
35 lines
905 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.api.endpoints import user, address, community
|
|
from app.models.database import Base, engine
|
|
|
|
# 创建数据库表
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="闪兔到家",
|
|
description="API 文档",
|
|
version="1.0.0"
|
|
)
|
|
|
|
# 配置 CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 添加用户路由
|
|
app.include_router(user.router, prefix="/api/user", tags=["用户"])
|
|
app.include_router(address.router, prefix="/api/address", tags=["配送地址"])
|
|
app.include_router(community.router, prefix="/api/community", tags=["社区"])
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "欢迎使用 FastAPI!"}
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy"} |