diff --git a/app.py b/app.py index 9209c36..8b2fb5e 100644 --- a/app.py +++ b/app.py @@ -132,15 +132,36 @@ app.add_middleware( allow_headers=["*"], ) +# app.py +EXACT_PROXY_PATHS = { + "/reslevis/postGateway", + "/reslevis/updateGateway", + "/reslevis/postTracker", + "/reslevis/updateTracker", + "/reslevis/postTrack", + "/reslevis/updateTrack", + "/reslevis/postZone", + "/reslevis/updateZone", +} + +PREFIX_PROXY_PATHS = { + "/reslevis/removeGateway/", + "/reslevis/removeTracker/", + "/reslevis/removeTrack/", + "/reslevis/removeZone/", +} + +def _should_proxy(path: str) -> bool: + return path in EXACT_PROXY_PATHS or any(path.startswith(p) for p in PREFIX_PROXY_PATHS) + #ResLevis CORE middleware @app.middleware("http") async def local_then_core(request: Request, call_next): - # only proxy CRUD for Reslevis (change prefix or methods if needed) - if request.url.path.startswith("/reslevis/") and request.method in {"POST", "PUT", "DELETE", "PATCH"}: - body = await request.body() # raw body preserved - local_resp = await call_next(request) # local storage runs here + if request.method in {"POST", "PUT", "DELETE", "PATCH"} and _should_proxy(request.url.path): + body = await request.body() + local_resp = await call_next(request) if local_resp.status_code >= 400: - return local_resp # stop if local failed + return local_resp return await _forward_to_core(request, body) return await call_next(request) diff --git a/routes/reslevis.py b/routes/reslevis.py index d9cc507..bc7e2cb 100644 --- a/routes/reslevis.py +++ b/routes/reslevis.py @@ -72,14 +72,10 @@ tracker_zone_repo = TrackerZoneJsonRepository() CORE_GET_REPO_BY_PATH = { "/reslevis/getGateways": gateway_repo, - "/reslevis/getBuildings": building_repo, - "/reslevis/getFloors": floor_repo, "/reslevis/getZones": zone_repo, "/reslevis/getTrackers": tracker_repo, "/reslevis/getTrackerZones": tracker_zone_repo, "/reslevis/getTracks": track_repo, - "/reslevis/getOperators": operator_repo, - "/reslevis/getSubjects": subject_repo, }