20 lines
894 B
Python
20 lines
894 B
Python
from fastapi import APIRouter, Request, HTTPException
|
|
from app.config import UNIVERSES
|
|
from app.proxy import proxy_request
|
|
|
|
router = APIRouter(prefix="/u", tags=["Universe Proxy"])
|
|
|
|
@router.api_route("/{universe_id}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
|
|
@router.api_route("/{universe_id}/", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
|
|
@router.api_route("/{universe_id}/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
|
|
async def dynamic_universe_proxy(universe_id: str, request: Request, path: str = ""):
|
|
if universe_id not in UNIVERSES:
|
|
raise HTTPException(status_code=404, detail=f"Universe '{universe_id}' not found.")
|
|
|
|
universe = UNIVERSES[universe_id]
|
|
return await proxy_request(
|
|
request=request,
|
|
backend_url=universe.backend_url,
|
|
path=path
|
|
)
|