Browse Source

fix some types + serve static files more easily

Getty Ritter 4 years ago
parent
commit
6f82d57e5d
2 changed files with 4 additions and 11 deletions
  1. 3 10
      parley.py
  2. 1 1
      storage.py

+ 3 - 10
parley.py

@@ -9,18 +9,11 @@ cache = storage.Cache()
 db = storage.Storage()
 
 
-@app.route("/static/<f>")
-async def static(request: sanic.request.Request, f: str) -> sanic.response.Response:
-    return await sanic.response.file('static/{}'.format(f))
-
-
-@app.route("/")
-async def index(request: sanic.request.Request) -> sanic.response.Response:
-    return await sanic.response.file('static/index.html')
-
+app.static('/static', './static')
+app.static('/', './static/index.html')
 
 @app.websocket("/socket")
-async def socket(request: sanic.request.Request, ws: sanic.websocket.WebSocketConnection) -> sanic.response.Response:
+async def socket(request: sanic.request.Request, ws: sanic.websocket.WebSocketConnection) -> sanic.response.HTTPResponse:
     initial = await ws.recv()
     config: messages.InitialConfig = messages.Message.decode(initial)
     sanic.log.logger.info(

+ 1 - 1
storage.py

@@ -1,4 +1,4 @@
-from sanic import WebSocketConnection # type: ignore
+from sanic.websocket import WebSocketConnection # type: ignore
 import sqlite3 as sql
 from typing import Dict, List, Optional, Tuple