64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
import asyncio
|
|
import json
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import HTMLResponse, PlainTextResponse
|
|
|
|
from .settings import settings
|
|
from .user import user_auth
|
|
from .map_tiles import map_tiles, map_meta
|
|
from .templates import j2env
|
|
from .monitoring import monitoring, ws_manager
|
|
|
|
app = FastAPI()
|
|
|
|
app.mount("/user/", user_auth)
|
|
app.mount("/map/", map_meta)
|
|
app.mount("/tiles/", map_tiles)
|
|
app.mount("/ipmi/", monitoring)
|
|
|
|
installer = j2env.get_template("install.lua").render(deploy_path=settings.deploy_path)
|
|
|
|
|
|
@app.get("/install")
|
|
async def get_installer():
|
|
return PlainTextResponse(installer)
|
|
|
|
|
|
app.mount("/lua/", StaticFiles(directory=settings.lua_out_path))
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def on_startup():
|
|
asyncio.get_running_loop().create_task(ws_manager.queue_task())
|
|
|
|
|
|
frontend = FastAPI()
|
|
|
|
manifest = dict()
|
|
if not settings.dev_mode:
|
|
with open(f"{settings.frontend_path}/manifest.json", "r") as f:
|
|
manifest = json.load(f)
|
|
|
|
|
|
index = j2env.get_template("index.html").render(
|
|
dev_mode=settings.dev_mode,
|
|
manifest=manifest,
|
|
)
|
|
|
|
|
|
@frontend.middleware("http")
|
|
async def index_catch_all(request: Request, call_next):
|
|
response = await call_next(request)
|
|
|
|
if response.status_code == 404:
|
|
return HTMLResponse(index)
|
|
|
|
return response
|
|
|
|
|
|
if not settings.dev_mode:
|
|
frontend.mount("/", StaticFiles(directory=settings.frontend_path))
|
|
|
|
app.mount("/", frontend)
|