add tornado for static file serving

This commit is contained in:
2021-04-01 00:32:18 +02:00
parent 452419dca2
commit 6efe870f59
3 changed files with 70 additions and 3 deletions

19
main.py
View File

@@ -2,6 +2,7 @@
# WS server example that synchronizes state across clients
import os
import asyncio
import json
import logging
@@ -10,6 +11,8 @@ import processor
import random
import time
import state
import tornado.ioloop
import tornado.web
logging.basicConfig()
@@ -69,7 +72,7 @@ async def counter(websocket, path):
finally:
await unregister(websocket)
async def serve():
async def serve_ws():
state.register_callback(notify_state)
await state.inc_initialized()
start_server = websockets.serve(counter, "localhost", 6789)
@@ -80,11 +83,23 @@ async def tick():
logging.warning("tick")
await asyncio.sleep(1)
async def serve_http():
settings={
"static_path": os.path.join(os.path.dirname(__file__), "frontend"),
"static_url_prefix": "/",
"static_handler_args": dict(default_filename="index.html")
}
app = tornado.web.Application(
[ (r"/(.*)", tornado.web.StaticFileHandler, dict(path=settings['static_path'], default_filename="index.html")) ],
**settings)
app.listen(8888)
async def main():
random.seed(time.time())
await asyncio.gather(
tick(),
serve(),
serve_ws(),
serve_http(),
processor.main(["192.168.178.123", "192.168.178.124"]),
)