fix launching backend without a built frontend

This commit is contained in:
Yeicor
2024-03-03 20:41:44 +01:00
parent 94e316472a
commit 4bd025e7d5

View File

@@ -28,6 +28,7 @@ if not os.path.exists(FRONTEND_BASE_PATH):
FRONTEND_BASE_PATH = os.path.join(FILE_DIR, '..', 'dist') FRONTEND_BASE_PATH = os.path.join(FILE_DIR, '..', 'dist')
else: else:
logger.warning('Frontend not found at %s', FRONTEND_BASE_PATH) logger.warning('Frontend not found at %s', FRONTEND_BASE_PATH)
FRONTEND_BASE_PATH = None
# Define the API paths (also available at the root path for simplicity) # Define the API paths (also available at the root path for simplicity)
UPDATES_API_PATH = '/api/updates' UPDATES_API_PATH = '/api/updates'
@@ -84,7 +85,8 @@ class Server:
self.app.router.add_get('/', self._entrypoint) self.app.router.add_get('/', self._entrypoint)
# - Static files from the frontend # - Static files from the frontend
self.app.router.add_get('/{path:(.*/|)}', _index_handler) # Any folder -> index.html self.app.router.add_get('/{path:(.*/|)}', _index_handler) # Any folder -> index.html
self.app.router.add_static('/', path=FRONTEND_BASE_PATH, name='static_frontend') if FRONTEND_BASE_PATH is not None:
self.app.router.add_static('/', path=FRONTEND_BASE_PATH, name='static_frontend')
# --- CORS --- # --- CORS ---
cors = aiohttp_cors.setup(self.app, defaults={ cors = aiohttp_cors.setup(self.app, defaults={
"*": aiohttp_cors.ResourceOptions( "*": aiohttp_cors.ResourceOptions(