Przeglądaj źródła

core sync bugfix

sync_core
Lorenzo Pollutri 5 dni temu
rodzic
commit
6ca4ff7cb8
2 zmienionych plików z 26 dodań i 9 usunięć
  1. +26
    -5
      app.py
  2. +0
    -4
      routes/reslevis.py

+ 26
- 5
app.py Wyświetl plik

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



+ 0
- 4
routes/reslevis.py Wyświetl plik

@@ -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,
}




Ładowanie…
Anuluj
Zapisz