Merge pull request #240 from tiqi-group/fix/enable-web-argument

Fix: enable web argument handling
This commit is contained in:
Mose Müller
2025-06-19 09:53:29 +02:00
committed by GitHub
2 changed files with 22 additions and 18 deletions

View File

@ -226,11 +226,11 @@ class Server:
server_task = self._loop.create_task(addin_server.serve())
server_task.add_done_callback(self._handle_server_shutdown)
self.servers[server_name] = server_task
if self._enable_web:
self._web_server = WebServer(
data_service_observer=self._observer,
host=self._host,
port=self._web_port,
enable_frontend=self._enable_web,
**self._kwargs,
)
server_task = self._loop.create_task(self._web_server.serve())
@ -319,7 +319,7 @@ class Server:
# here we exclude most kinds of exceptions from triggering this kind of shutdown
exc = context.get("exception")
if type(exc) not in [RuntimeError, KeyboardInterrupt, asyncio.CancelledError]:
if self._enable_web:
if loop.is_running():
async def emit_exception() -> None:
try:

View File

@ -81,6 +81,7 @@ class WebServer:
host: str,
port: int,
*,
enable_frontend: bool = True,
css: str | Path | None = None,
favicon_path: str | Path | None = None,
enable_cors: bool = True,
@ -97,6 +98,7 @@ class WebServer:
self.enable_cors = enable_cors
self.frontend_src = frontend_src
self.favicon_path: Path | str = favicon_path # type: ignore
self.enable_frontend = enable_frontend
if self.favicon_path is None:
self.favicon_path = self.frontend_src / "favicon.ico"
@ -162,6 +164,7 @@ class WebServer:
# Define routes
self._sio.attach(app, socketio_path="/ws/socket.io")
if self.enable_frontend:
app.router.add_static("/assets", self.frontend_src / "assets")
app.router.add_get("/favicon.ico", self._favicon_route)
app.router.add_get("/service-properties", self._service_properties_route)
@ -169,6 +172,7 @@ class WebServer:
app.router.add_get("/custom.css", self._styles_route)
app.add_subapp("/api/", create_api_application(self.state_manager))
if self.enable_frontend:
app.router.add_get(r"/", index)
app.router.add_get(r"/{tail:.*}", index)