Skip to content

Commit

Permalink
fix(http): Automatically server index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Aug 10, 2021
1 parent da0704f commit e43dde4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/src/wslink/backends/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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():
Expand Down Expand Up @@ -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"]:
Expand Down
3 changes: 3 additions & 0 deletions python/src/wslink/backends/aiohttp/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import aiohttp.web as aiohttp_web

from . import _root_handler

from wslink.launcher import (
SessionManager,
ProxyMappingManagerTXT,
Expand Down Expand Up @@ -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)
7 changes: 7 additions & 0 deletions python/src/wslink/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =============================================================================
Expand Down

0 comments on commit e43dde4

Please sign in to comment.