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 @@ + + + + gischat + + +

gischat websocket client

+
+ + + + +
+ + + +
+ + + +
+
+ + + + diff --git a/gischat/ws_html.py b/gischat/ws_html.py deleted file mode 100755 index 365f3ec..0000000 --- a/gischat/ws_html.py +++ /dev/null @@ -1,71 +0,0 @@ -ws_html = """ - - - - gischat - - -

gischat websocket client

-
- - - - -
- - - -
-
- - - - -""" diff --git a/poetry.lock b/poetry.lock index bfcfdad..cb7530d 100755 --- a/poetry.lock +++ b/poetry.lock @@ -1530,4 +1530,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "bc71e7e743c52fc139a1d64d3eab3028ab161652df65dfb76706d5cf4e233e00" +content-hash = "39f7ee63d354675a34c5cb01541010a63197f65e571b2fdb3d744ed5467741a8" diff --git a/pyproject.toml b/pyproject.toml index ea71c2d..a65af92 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ colorlog = "^6.8.2" websockets = "^12.0" pydantic = "^2.8.2" toml = "^0.10.2" +jinja2 = "^3.1.4" [tool.poetry.group.dev.dependencies] pre-commit = "^3.7.1"