commit 0947c140270e1f20b8a631aa7838fe9dbc5c7b8a Author: Dan Date: Sat Jun 20 22:19:44 2026 -0600 Initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b85dd30 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY main.py . + +EXPOSE 8080 + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0ac0c80 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + portainer-proxy: + build: . + image: portainer-proxy:latest + container_name: portainer-proxy + restart: unless-stopped + ports: + - "8080:8080" + environment: + - PORTAINER_URL=http://192.168.0.62:9000 + networks: + - traefik-public + +networks: + traefik-public: + external: true diff --git a/main.py b/main.py new file mode 100644 index 0000000..32922df --- /dev/null +++ b/main.py @@ -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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d23d558 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fastapi +uvicorn +httpx