betterwithage commited on
Commit
1316d5b
·
verified ·
1 Parent(s): 74887fd

Fix: FLEET routes front-inserted after frontier patch so they win over SPA catch-all

Browse files

The killinchu_frontier_patch.register() does routes.clear()+extend which reordered the FLEET (vessels) routes behind the /{full_path:path} catch-all, causing /api/killinchu/v1/fleet/* to 404. Re-register the 8 FLEET routes (vessels, forecast-modules, predictive-maintenance, compliance-certificates, port-state-deficiencies, ai-briefings, all, voyage-risk) at position 0 of app.router.routes AFTER the frontier patch runs, guaranteeing precedence. ADDITIVE, no mocks, data served verbatim from embedded platform seed-data.

Files changed (1) hide show
  1. serve.py +61 -0
serve.py CHANGED
@@ -2462,3 +2462,64 @@ except Exception as _killinchu_dag_e:
2462
  # ============================================================================
2463
  # END: /khipu/dag ALIAS — killinchu
2464
  # ============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2462
  # ============================================================================
2463
  # END: /khipu/dag ALIAS — killinchu
2464
  # ============================================================================
2465
+
2466
+
2467
+ # ============================================================================
2468
+ # FLEET (Vessels) FRONT-INSERT — runs LAST, after killinchu_frontier_patch's
2469
+ # routes.clear()+extend, so the FLEET routes are guaranteed to sit AHEAD of the
2470
+ # /{full_path:path} SPA catch-all (which 404s anything under api/). The earlier
2471
+ # include_router at ~line 1689 is harmless; this re-inserts the same routes at
2472
+ # position 0 to win precedence on the HF runtime. ADDITIVE ONLY. NO mocks.
2473
+ # ============================================================================
2474
+ try:
2475
+ import sys as _fleet2_sys
2476
+ from fastapi.routing import APIRoute as _Fleet2Route
2477
+ from fastapi.responses import JSONResponse as _Fleet2JR
2478
+ import killinchu_fleet_vessels as _fleet2
2479
+ _fleet2_data = _fleet2._load()
2480
+ _FLEET2_LABEL = _fleet2.HONESTY_LABEL
2481
+ _fleet2_base = "/api/killinchu/v1/fleet"
2482
+
2483
+ def _fleet2_make(key):
2484
+ async def _h() -> _Fleet2JR:
2485
+ return _Fleet2JR({"data": _fleet2_data.get(key, []),
2486
+ "honesty": _FLEET2_LABEL, "source_key": key})
2487
+ return _h
2488
+
2489
+ async def _fleet2_all() -> _Fleet2JR:
2490
+ return _Fleet2JR({"datasets": _fleet2_data,
2491
+ "counts": {k: (len(v) if isinstance(v, list) else None)
2492
+ for k, v in _fleet2_data.items()},
2493
+ "honesty": _FLEET2_LABEL,
2494
+ "source": "github.com/szl-holdings/platform seed-data/vessels/*"})
2495
+
2496
+ async def _fleet2_voyage() -> _Fleet2JR:
2497
+ return _Fleet2JR(_fleet2.voyage_risk_loop())
2498
+
2499
+ _fleet2_specs = [
2500
+ ("/vessels", _fleet2_make("vessels"), "fleet_vessels"),
2501
+ ("/forecast-modules", _fleet2_make("forecast-modules"), "fleet_forecast_modules"),
2502
+ ("/predictive-maintenance", _fleet2_make("predictive-maintenance"), "fleet_predictive_maintenance"),
2503
+ ("/compliance-certificates", _fleet2_make("compliance-certificates"), "fleet_compliance_certificates"),
2504
+ ("/port-state-deficiencies", _fleet2_make("port-state-deficiencies"), "fleet_port_state_deficiencies"),
2505
+ ("/ai-briefings", _fleet2_make("ai-briefings"), "fleet_ai_briefings"),
2506
+ ("/all", _fleet2_all, "fleet_all"),
2507
+ ("/voyage-risk", _fleet2_voyage, "fleet_voyage_risk"),
2508
+ ]
2509
+ _fleet2_names = {n for _, _, n in _fleet2_specs}
2510
+ # Drop any prior copies (from the early include_router) to avoid duplicates.
2511
+ app.router.routes[:] = [r for r in app.router.routes
2512
+ if getattr(r, "name", "") not in _fleet2_names]
2513
+ _fleet2_new = [_Fleet2Route(f"{_fleet2_base}{p}", h, methods=["GET"], name=n)
2514
+ for p, h, n in _fleet2_specs]
2515
+ for _r in reversed(_fleet2_new):
2516
+ app.router.routes.insert(0, _r)
2517
+ print(f"[killinchu] FLEET front-insert OK: {len(_fleet2_new)} routes ahead of catch-all",
2518
+ file=_fleet2_sys.stderr)
2519
+ except Exception as _fleet2_e:
2520
+ import sys as _fleet2_sys, traceback as _fleet2_tb
2521
+ print(f"[killinchu] FLEET front-insert FAILED: {_fleet2_e!r}", file=_fleet2_sys.stderr)
2522
+ _fleet2_tb.print_exc(file=_fleet2_sys.stderr)
2523
+ # ============================================================================
2524
+ # END: FLEET (Vessels) FRONT-INSERT
2525
+ # ============================================================================