mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-23 20:47:59 +02:00
Merge pull request #240 from tiqi-group/fix/enable-web-argument
Fix: enable web argument handling
This commit is contained in:
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user