add tornado for static file serving
This commit is contained in:
19
main.py
19
main.py
@@ -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"]),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user