From 4ea3a099b05fa910498bfbf1b2d7387118355472 Mon Sep 17 00:00:00 2001 From: "Ole Mathias Aa. Heggem" Date: Sun, 13 Apr 2025 07:18:45 +0200 Subject: Upgrade bootstrap and rewrite API (#230) --- web/dev-server/main.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 web/dev-server/main.py (limited to 'web/dev-server/main.py') diff --git a/web/dev-server/main.py b/web/dev-server/main.py new file mode 100644 index 0000000..ab0adf2 --- /dev/null +++ b/web/dev-server/main.py @@ -0,0 +1,34 @@ +import os +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +from starlette.responses import Response, FileResponse +import httpx +from dotenv import load_dotenv + +app = FastAPI() +load_dotenv() + +auth = httpx.BasicAuth(username=os.environ.get("GONDUL_USERNAME"), password=os.environ.get("GONDUL_PASSWORD")) + +@app.get("/") +async def root(): + return FileResponse("../index.html") + +@app.get("/api/{path:path}") +async def tile_request(path: str, response: Response): + async with httpx.AsyncClient() as client: + proxy = await client.get(f"{os.environ.get("GONDUL_URL")}/api/{path}", auth=auth) + response.body = proxy.content + response.status_code = proxy.status_code + return response + +@app.post("/api/{path:path}") +async def tile_post_request(path: str, response: Response): + async with httpx.AsyncClient() as client: + proxy = await client.get(f"{os.environ.get("GONDUL_URL")}/api/{path}", auth=auth) + response.body = proxy.content + response.status_code = proxy.status_code + return response + +# Mount web root +app.mount("/", StaticFiles(directory="../")) \ No newline at end of file -- cgit v1.2.3