45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
|
|
from fastapi import FastAPI, Request, Depends
|
||
|
|
from fastapi.middleware.cors import CORSMiddleware
|
||
|
|
from app.api import auth, users, orders, payments
|
||
|
|
from app.core.config import settings
|
||
|
|
from app.db.database import engine, Base
|
||
|
|
from app.middleware.error_handler import error_handler
|
||
|
|
from fastapi.exceptions import RequestValidationError
|
||
|
|
from starlette.exceptions import HTTPException as StarletteHTTPException
|
||
|
|
|
||
|
|
# Create database tables
|
||
|
|
Base.metadata.create_all(bind=engine)
|
||
|
|
|
||
|
|
app = FastAPI(
|
||
|
|
title="活牛采购智能数字化系统API",
|
||
|
|
description="活牛采购智能数字化系统后端API接口",
|
||
|
|
version="1.0.0",
|
||
|
|
)
|
||
|
|
|
||
|
|
# Add CORS middleware
|
||
|
|
app.add_middleware(
|
||
|
|
CORSMiddleware,
|
||
|
|
allow_origins=["*"], # In production, specify exact origins
|
||
|
|
allow_credentials=True,
|
||
|
|
allow_methods=["*"],
|
||
|
|
allow_headers=["*"],
|
||
|
|
)
|
||
|
|
|
||
|
|
# Add exception handlers
|
||
|
|
app.add_exception_handler(StarletteHTTPException, error_handler)
|
||
|
|
app.add_exception_handler(RequestValidationError, error_handler)
|
||
|
|
app.add_exception_handler(Exception, error_handler)
|
||
|
|
|
||
|
|
# Include routers
|
||
|
|
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
|
||
|
|
app.include_router(users.router, prefix="/api/users", tags=["users"])
|
||
|
|
app.include_router(orders.router, prefix="/api/orders", tags=["orders"])
|
||
|
|
app.include_router(payments.router, prefix="/api/payments", tags=["payments"])
|
||
|
|
|
||
|
|
@app.get("/")
|
||
|
|
async def root():
|
||
|
|
return {"message": "活牛采购智能数字化系统后端服务", "version": "1.0.0"}
|
||
|
|
|
||
|
|
@app.get("/health")
|
||
|
|
async def health_check():
|
||
|
|
return {"status": "healthy"}
|