diff --git a/gischat/app.py b/gischat/app.py index 8807e77..b60acb1 100755 --- a/gischat/app.py +++ b/gischat/app.py @@ -4,14 +4,14 @@ import sys import colorlog -from fastapi import FastAPI, HTTPException, WebSocket +from fastapi import FastAPI, HTTPException, Request, WebSocket from fastapi.encoders import jsonable_encoder from fastapi.responses import HTMLResponse +from fastapi.templating import Jinja2Templates from starlette.websockets import WebSocketDisconnect from gischat.models import MessageModel, RulesModel, StatusModel, VersionModel from gischat.utils import get_poetry_version -from gischat.ws_html import ws_html # logger logger = logging.getLogger() @@ -74,11 +74,15 @@ async def notify(self, room: str, message: str): summary="Chat with your GIS tribe in QGIS, QField and other clients !", version=get_poetry_version(), ) +templates = Jinja2Templates(directory="gischat/templates") -@app.get("/") -async def get_ws_page(): - return HTMLResponse(ws_html) +@app.get("/", response_class=HTMLResponse) +async def get_ws_page(request: Request): + return templates.TemplateResponse( + request=request, + name="ws-page.html", + ) @app.get("/version", response_model=VersionModel) diff --git a/gischat/templates/ws-page.html b/gischat/templates/ws-page.html new file mode 100644 index 0000000..c87cbf6 --- /dev/null +++ b/gischat/templates/ws-page.html @@ -0,0 +1,121 @@ + + +
+