aboutsummaryrefslogtreecommitdiffstats
path: root/web/dev-server/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'web/dev-server/main.py')
-rw-r--r--web/dev-server/main.py34
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