From 26c81effd620a310a3df18406678f9d6831ba3de Mon Sep 17 00:00:00 2001 From: Ari Date: Sat, 4 Jun 2022 17:54:32 -0400 Subject: [PATCH] fixed routing issue --- Makefile | 1 - api/src/api/app.py | 14 +++++++++----- api/src/env.py | 1 + webapp/src/apiService/index.ts | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7cee24f..9bc4470 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ push: $(DC) push start: - $(MAKE) build $(DC) up -d sleep 1 $(DC) ps diff --git a/api/src/api/app.py b/api/src/api/app.py index 47ff9d6..9682cd8 100644 --- a/api/src/api/app.py +++ b/api/src/api/app.py @@ -3,7 +3,7 @@ from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles from src.automations.manager import AutomationManager -from src.env import ORIGIN, ROOT_FOLDER +from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER from .routes import automations, details, ping, socket @@ -12,7 +12,7 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI: app = FastAPI() if (ROOT_FOLDER / "web").exists(): app.mount( - "/web", + f"{API_PREFIX}/web", StaticFiles( directory=ROOT_FOLDER / "web", html=True, @@ -29,7 +29,11 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI: allow_headers=["*"], ) app.include_router(ping.router, prefix="/ping") - app.include_router(automations.make_automation_router(automation_mgr), prefix="/automations") - app.include_router(details.make_details_router(automation_mgr.hass_config), prefix="/details") - app.include_router(socket.router, prefix="/socket") + app.include_router( + automations.make_automation_router(automation_mgr), prefix=f"{API_PREFIX}/automations" + ) + app.include_router( + details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details" + ) + app.include_router(socket.router, prefix=f"{API_PREFIX}/socket") return app diff --git a/api/src/env.py b/api/src/env.py index d27e95e..5dbd437 100644 --- a/api/src/env.py +++ b/api/src/env.py @@ -7,4 +7,5 @@ BUILD_VERSION = config("BUILD_VERSION", "0.0.0") HASSIO_TOKEN = config("SUPERVISOR_TOKEN", "") HASSIO_WS = config("HASSIO_WS", "ws://supervisor/core/websocket") LOG_LEVEL = config("LOG_LEVEL", "INFO") +API_PREFIX = config("API_PREFIX", "") ORIGIN = config("ORIGIN", cast=Csv(), default="*") diff --git a/webapp/src/apiService/index.ts b/webapp/src/apiService/index.ts index 30c8e21..895b0cb 100644 --- a/webapp/src/apiService/index.ts +++ b/webapp/src/apiService/index.ts @@ -4,7 +4,7 @@ import { makeRemoteAPI } from "./base"; import { useAPIService } from './core'; import { useMockAPI } from "./mock"; -const locationPrefixWeb = window.location.pathname.match(/(.+)\/web/i); +const locationPrefixWeb = window.location.pathname.match(/(\/.+\/)web/i); const baseURL = new URL( process.env.NODE_ENV === 'development' ? "http://localhost:8000" :