Add versioned HTTP gateway routing by business domain
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from adcloud_server.schemas import ModuleHealthResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health", response_model=ModuleHealthResponse)
|
||||
def health() -> ModuleHealthResponse:
|
||||
"""Verify routing to the ads module; not a dependency readiness check."""
|
||||
return ModuleHealthResponse(module="ads")
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from adcloud_server.schemas import ModuleHealthResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health", response_model=ModuleHealthResponse)
|
||||
def health() -> ModuleHealthResponse:
|
||||
"""Verify routing to the events module; not a dependency readiness check."""
|
||||
return ModuleHealthResponse(module="events")
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from adcloud_server.schemas import ModuleHealthResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health", response_model=ModuleHealthResponse)
|
||||
def health() -> ModuleHealthResponse:
|
||||
"""Verify routing to the identity module; not a dependency readiness check."""
|
||||
return ModuleHealthResponse(module="identity")
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from adcloud_server.api.v1 import ads, events, identity, users
|
||||
|
||||
router = APIRouter(prefix="/v1")
|
||||
router.include_router(events.router, prefix="/events", tags=["events"])
|
||||
router.include_router(users.router, prefix="/users", tags=["users"])
|
||||
router.include_router(ads.router, prefix="/ads", tags=["ads"])
|
||||
router.include_router(identity.router, prefix="/identity", tags=["identity"])
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from adcloud_server.schemas import ModuleHealthResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health", response_model=ModuleHealthResponse)
|
||||
def health() -> ModuleHealthResponse:
|
||||
"""Verify routing to the users module; not a dependency readiness check."""
|
||||
return ModuleHealthResponse(module="users")
|
||||
+30
-20
@@ -1,29 +1,39 @@
|
||||
import os
|
||||
from typing import Literal
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI(title="AdCloud Server", version="0.1.0")
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
origin.strip()
|
||||
for origin in os.getenv(
|
||||
"CORS_ORIGINS", "http://localhost:3000,http://localhost:5173"
|
||||
).split(",")
|
||||
if origin.strip()
|
||||
],
|
||||
allow_methods=["GET"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
from adcloud_server.api.v1.router import router as v1_router
|
||||
from adcloud_server.schemas import HealthResponse
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: Literal["ok"] = "ok"
|
||||
def create_app() -> FastAPI:
|
||||
application = FastAPI(
|
||||
title="AdCloud Server",
|
||||
version="0.1.0",
|
||||
description="Versioned HTTP API for AdCloud tracking and ad delivery.",
|
||||
redirect_slashes=False,
|
||||
)
|
||||
application.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
origin.strip()
|
||||
for origin in os.getenv(
|
||||
"CORS_ORIGINS",
|
||||
"http://localhost:3000,http://localhost:5173,http://localhost:5174",
|
||||
).split(",")
|
||||
if origin.strip()
|
||||
],
|
||||
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
allow_headers=["Authorization", "Content-Type", "X-Request-ID"],
|
||||
)
|
||||
application.include_router(v1_router)
|
||||
|
||||
@application.get("/health", response_model=HealthResponse, tags=["system"])
|
||||
def health() -> HealthResponse:
|
||||
return HealthResponse()
|
||||
|
||||
return application
|
||||
|
||||
|
||||
@app.get("/health", response_model=HealthResponse)
|
||||
def health() -> HealthResponse:
|
||||
return HealthResponse()
|
||||
app = create_app()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: Literal["ok"] = "ok"
|
||||
|
||||
|
||||
class ModuleHealthResponse(HealthResponse):
|
||||
module: Literal["events", "users", "ads", "identity"]
|
||||
Reference in New Issue
Block a user