rebuild(stage-1): establish isolated application skeleton
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""HTTP delivery layer."""
|
||||
@@ -0,0 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
def install_error_handlers(application: FastAPI) -> None:
|
||||
@application.exception_handler(Exception)
|
||||
async def unexpected_error(_request: Request, _error: Exception) -> JSONResponse:
|
||||
correlation_id = uuid.uuid4().hex
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={
|
||||
"error": {
|
||||
"code": "internal_error",
|
||||
"message": "服务暂时不可用,请稍后重试。",
|
||||
"correlation_id": correlation_id,
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from backend.http.routes.health import router as health_router
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(health_router)
|
||||
@@ -0,0 +1 @@
|
||||
"""Transport-only route modules."""
|
||||
@@ -0,0 +1,17 @@
|
||||
from fastapi import APIRouter, Request
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: str
|
||||
environment: str
|
||||
|
||||
|
||||
@router.get("/health", response_model=HealthResponse)
|
||||
def health(request: Request) -> HealthResponse:
|
||||
return HealthResponse(
|
||||
status="ok",
|
||||
environment=request.app.state.settings.environment,
|
||||
)
|
||||
Reference in New Issue
Block a user