diff options
author | Ole Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com> | 2025-04-13 07:18:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-13 07:18:45 +0200 |
commit | 4ea3a099b05fa910498bfbf1b2d7387118355472 (patch) | |
tree | c248cf6764412471ee3e0d1218761bee19fb396a /web/dev-server/main.py | |
parent | 09710c061d5b8ae86b3dfe49f4b8936c13a10535 (diff) |
Diffstat (limited to 'web/dev-server/main.py')
-rw-r--r-- | web/dev-server/main.py | 34 |
1 files changed, 34 insertions, 0 deletions
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 |