|
@@ -2,17 +2,14 @@ import secrets
|
|
|
import logging
|
|
|
import dbm
|
|
|
from collections import defaultdict
|
|
|
+from mimetypes import guess_type
|
|
|
|
|
|
from asyncio.queues import Queue
|
|
|
-from fastapi import (
|
|
|
- FastAPI,
|
|
|
- WebSocket,
|
|
|
- HTTPException,
|
|
|
- Depends,
|
|
|
- status,
|
|
|
-)
|
|
|
+from fastapi import FastAPI, WebSocket, HTTPException, Depends, status, Response
|
|
|
from starlette.websockets import WebSocketDisconnect
|
|
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
|
|
+from fastapi.encoders import jsonable_encoder
|
|
|
+from fastapi.staticfiles import StaticFiles
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
@@ -86,6 +83,7 @@ class Manager:
|
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
+app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
manager = Manager()
|
|
|
counter_store = Store(
|
|
|
n=1, db_path="/var/lib/pizzicore/pizzicore.dbm", manager=manager
|
|
@@ -148,3 +146,15 @@ async def websocket_counter(websocket: WebSocket, cid: int):
|
|
|
manager.unsubscribe(cid, q)
|
|
|
return
|
|
|
await q.get()
|
|
|
+
|
|
|
+
|
|
|
+async def get_page(fname):
|
|
|
+ with open(fname) as f:
|
|
|
+ content = f.read()
|
|
|
+ content_type, _ = guess_type(fname)
|
|
|
+ return Response(content, media_type=content_type)
|
|
|
+
|
|
|
+
|
|
|
+@app.get("/")
|
|
|
+async def root_page():
|
|
|
+ return await get_page("pages/index.html")
|