diff --git a/python/src/wslink/backends/aiohttp/__init__.py b/python/src/wslink/backends/aiohttp/__init__.py index 55092789..766c0c04 100644 --- a/python/src/wslink/backends/aiohttp/__init__.py +++ b/python/src/wslink/backends/aiohttp/__init__.py @@ -15,6 +15,7 @@ import aiohttp import aiohttp.web as aiohttp_web + async def _on_startup(app): # Emit an expected log message so launcher.py knows we've started up. logging.critical("wslink: Starting factory") @@ -30,6 +31,10 @@ def _schedule_shutdown(app): app["state"]["shutdown_task"] = schedule_coroutine(timeout, _stop_server, app) +async def _root_handler(request): + return aiohttp.web.HTTPFound("/index.html") + + async def _stop_server(app): # Disconnecting any connected clients of handler(s) for route, handler in app["state"]["server_config"]["ws"].items(): @@ -123,6 +128,8 @@ def create_webserver(server_config): for route, server_path in static_routes.items(): routes.append(aiohttp_web.static(_fix_path(route), server_path)) + # Resolve / => /index.html + web_app.router.add_route("GET", "/", _root_handler) web_app.add_routes(routes) if "logging_level" in server_config and server_config["logging_level"]: diff --git a/python/src/wslink/backends/aiohttp/launcher.py b/python/src/wslink/backends/aiohttp/launcher.py index 90f77350..d1f9b5bc 100644 --- a/python/src/wslink/backends/aiohttp/launcher.py +++ b/python/src/wslink/backends/aiohttp/launcher.py @@ -16,6 +16,8 @@ import aiohttp.web as aiohttp_web +from . import _root_handler + from wslink.launcher import ( SessionManager, ProxyMappingManagerTXT, @@ -237,6 +239,7 @@ def startWebServer(options, config): ) if len(content) > 0: + web_app.router.add_route("GET", "/", _root_handler) web_app.add_routes([aiohttp_web.static("/", content)]) aiohttp_web.run_app(web_app, host=host, port=port) diff --git a/python/src/wslink/launcher.py b/python/src/wslink/launcher.py index fd5be4d1..ee4a1d2c 100755 --- a/python/src/wslink/launcher.py +++ b/python/src/wslink/launcher.py @@ -587,6 +587,13 @@ def start(argv=None, description="wslink Web Launcher"): backends.launcher_start(args, config, backend=args.backend) +# Used for backward compatibility + + +def startWebServer(args, config, backend="aiohttp"): + return backends.launcher_start(args, config, backend=backend) + + # ============================================================================= # Main # =============================================================================