重构后端服务架构并优化前端错误处理

This commit is contained in:
ylweng
2025-09-12 01:21:43 +08:00
parent d550a8ed51
commit 3a48a67757
53 changed files with 3925 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
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"}