Initial commit

This commit is contained in:
Dan
2026-06-20 22:19:44 -06:00
commit 0947c14027
4 changed files with 72 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
from fastapi import FastAPI, Request, HTTPException
from fastapi.middleware.cors import CORSMiddleware
import httpx
import os
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
PORTAINER_URL = os.getenv("PORTAINER_URL", "http://192.168.0.62:9000")
@app.get("/health")
async def health():
return {"status": "ok"}
@app.api_route("/api/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
async def proxy(path: str, request: Request):
token = request.headers.get("X-API-Key")
if not token:
raise HTTPException(status_code=401, detail="Missing API key")
url = f"{PORTAINER_URL}/api/{path}"
if request.url.query:
url += f"?{request.url.query}"
body = await request.body()
async with httpx.AsyncClient(timeout=30) as client:
response = await client.request(
method=request.method,
url=url,
headers={"X-API-Key": token, "Content-Type": "application/json"},
content=body,
)
return response.json()