register static route on run

This commit is contained in:
Izalia Mae 2024-03-15 21:28:40 -04:00
parent 6018af1e68
commit 2be96a8ca5

View file

@ -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())