Julian Bilcke
commited on
Commit
·
8cc1429
1
Parent(s):
d161f29
serve on /
Browse files- client/index.html +1 -1
- server.py +14 -2
client/index.html
CHANGED
|
@@ -233,6 +233,6 @@
|
|
| 233 |
</div>
|
| 234 |
</div>
|
| 235 |
|
| 236 |
-
<script src="client.js"></script>
|
| 237 |
</body>
|
| 238 |
</html>
|
|
|
|
| 233 |
</div>
|
| 234 |
</div>
|
| 235 |
|
| 236 |
+
<script src="/assets/client.js"></script>
|
| 237 |
</body>
|
| 238 |
</html>
|
server.py
CHANGED
|
@@ -477,6 +477,15 @@ async def status_handler(request: web.Request) -> web.Response:
|
|
| 477 |
'available_scenes': game_manager.valid_scenes
|
| 478 |
})
|
| 479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
async def websocket_handler(request: web.Request) -> web.WebSocketResponse:
|
| 481 |
ws = web.WebSocketResponse(
|
| 482 |
max_msg_size=1024*1024*10, # 10MB max message size
|
|
@@ -569,8 +578,11 @@ async def init_app() -> web.Application:
|
|
| 569 |
app.router.add_get('/ws', websocket_handler)
|
| 570 |
app.router.add_get('/api/status', status_handler)
|
| 571 |
|
| 572 |
-
#
|
| 573 |
-
app.router.
|
|
|
|
|
|
|
|
|
|
| 574 |
|
| 575 |
return app
|
| 576 |
|
|
|
|
| 477 |
'available_scenes': game_manager.valid_scenes
|
| 478 |
})
|
| 479 |
|
| 480 |
+
async def root_handler(request: web.Request) -> web.Response:
|
| 481 |
+
"""Handler for serving the client at the root path"""
|
| 482 |
+
client_path = pathlib.Path(__file__).parent / 'client' / 'index.html'
|
| 483 |
+
|
| 484 |
+
with open(client_path, 'r') as file:
|
| 485 |
+
html_content = file.read()
|
| 486 |
+
|
| 487 |
+
return web.Response(text=html_content, content_type='text/html')
|
| 488 |
+
|
| 489 |
async def websocket_handler(request: web.Request) -> web.WebSocketResponse:
|
| 490 |
ws = web.WebSocketResponse(
|
| 491 |
max_msg_size=1024*1024*10, # 10MB max message size
|
|
|
|
| 578 |
app.router.add_get('/ws', websocket_handler)
|
| 579 |
app.router.add_get('/api/status', status_handler)
|
| 580 |
|
| 581 |
+
# Serve the client at root path
|
| 582 |
+
app.router.add_get('/', root_handler)
|
| 583 |
+
|
| 584 |
+
# Set up static file serving for the client assets
|
| 585 |
+
app.router.add_static('/assets', path=pathlib.Path(__file__).parent / 'client')
|
| 586 |
|
| 587 |
return app
|
| 588 |
|