From 2be96a8ca5bfa2a2177fd67bbc496399c1d95c1d Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Fri, 15 Mar 2024 21:28:40 -0400 Subject: [PATCH] register static route on run --- relay/application.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/relay/application.py b/relay/application.py index 4d67826..ee5b465 100644 --- a/relay/application.py +++ b/relay/application.py @@ -71,14 +71,6 @@ class Application(web.Application): for path, view in VIEWS: self.router.add_view(path, view) - if self['dev']: - static = StaticResource('/static', get_resource('frontend/static')) - - else: - static = CachedStaticResource('/static', get_resource('frontend/static')) - - self.router.register_resource(static) - setup_swagger( self, ui_version = 3, @@ -154,6 +146,16 @@ class Application(web.Application): self['push_queue'].put((inbox, message, instance)) + def register_static_routes(self) -> None: + if self['dev']: + static = StaticResource('/static', get_resource('frontend/static')) + + else: + static = CachedStaticResource('/static', get_resource('frontend/static')) + + self.router.register_resource(static) + + def run(self) -> None: if self["running"]: return @@ -166,6 +168,8 @@ class Application(web.Application): logging.error(f'A server is already running on {host}:{port}') return + self.register_static_routes() + logging.info(f'Starting webserver at {domain} ({host}:{port})') asyncio.run(self.handle_run())