Hermes Agent commited on
Commit
55be8db
Β·
1 Parent(s): fdfbafc

fix(routing): enable Referer-based routing to resolve provider details page SyntaxError

Browse files
Files changed (1) hide show
  1. gateway/main.py +25 -14
gateway/main.py CHANGED
@@ -13,7 +13,7 @@ import os
13
  import logging
14
  from contextlib import asynccontextmanager
15
  from fastapi import FastAPI, Request, Response
16
- from fastapi.responses import JSONResponse, HTMLResponse, FileResponse
17
 
18
  from gateway.utils import (
19
  get_http_client,
@@ -92,16 +92,21 @@ async def route_catch_all(path: str, request: Request):
92
  referer = request.headers.get("referer", "").lower()
93
  req_path = request.url.path.lower()
94
 
95
- # ── 1. OmniRoute Explicit Management & API Endpoints ──────────────────────
96
- if req_path in ("/omniroute", "/omniroute/"):
97
- return RedirectResponse(url="/dashboard", status_code=307)
98
 
99
  OMNIROUTE_PREFIXES = (
100
  "/dashboard",
101
  "/omniroute",
102
  "/_next",
 
103
  "/api/providers",
 
104
  "/api/credentials",
 
 
 
 
 
105
  "/api/oauth",
106
  "/api/settings",
107
  "/api/monitoring",
@@ -117,7 +122,9 @@ async def route_catch_all(path: str, request: Request):
117
  "/api/vector",
118
  "/api/chats",
119
  "/api/tokens",
120
- "/api/cloud-agent-credentials",
 
 
121
  )
122
 
123
  OMNIROUTE_EXACT = (
@@ -132,18 +139,22 @@ async def route_catch_all(path: str, request: Request):
132
  "/callback",
133
  )
134
 
 
 
 
 
 
 
 
 
135
  if (
136
- any(req_path == p or req_path.startswith(p + "/") for p in OMNIROUTE_PREFIXES)
 
137
  or req_path in OMNIROUTE_EXACT
138
  ):
139
- logger.info(f"[ROUTER] {req_path} -> OmniRoute ({OMNIROUTE_PORT})")
140
- extra = {
141
- "Host": PUBLIC_HOST,
142
- "X-Forwarded-Host": PUBLIC_HOST,
143
- "X-Forwarded-Proto": "https",
144
- "X-Forwarded-Port": "443",
145
- }
146
- return await proxy_http_request(f"http://127.0.0.1:{OMNIROUTE_PORT}{req_path}", request, default_prefix="", extra_headers=extra)
147
 
148
  # ── 2. Jellyfin Media Server Namespace ────────────────────────────────────
149
  if req_path == "/jellyfin" or req_path.startswith("/jellyfin/"):
 
13
  import logging
14
  from contextlib import asynccontextmanager
15
  from fastapi import FastAPI, Request, Response
16
+ from fastapi.responses import JSONResponse, HTMLResponse, FileResponse, RedirectResponse
17
 
18
  from gateway.utils import (
19
  get_http_client,
 
92
  referer = request.headers.get("referer", "").lower()
93
  req_path = request.url.path.lower()
94
 
95
+ is_omniroute_referer = "/dashboard" in referer or "/omniroute" in referer or "/providers" in referer
 
 
96
 
97
  OMNIROUTE_PREFIXES = (
98
  "/dashboard",
99
  "/omniroute",
100
  "/_next",
101
+ "/providers",
102
  "/api/providers",
103
+ "/api/provider-",
104
  "/api/credentials",
105
+ "/api/connections",
106
+ "/api/custom-",
107
+ "/api/synced-",
108
+ "/api/token-",
109
+ "/api/sync/",
110
  "/api/oauth",
111
  "/api/settings",
112
  "/api/monitoring",
 
122
  "/api/vector",
123
  "/api/chats",
124
  "/api/tokens",
125
+ "/api/cloud-",
126
+ "/api/arena",
127
+ "/api/pricing",
128
  )
129
 
130
  OMNIROUTE_EXACT = (
 
139
  "/callback",
140
  )
141
 
142
+ extra = {
143
+ "Host": PUBLIC_HOST,
144
+ "X-Forwarded-Host": PUBLIC_HOST,
145
+ "X-Forwarded-Proto": "https",
146
+ "X-Forwarded-Port": "443",
147
+ }
148
+
149
+ # If request originates from OmniRoute Dashboard or matches OmniRoute prefixes, route to OmniRoute
150
  if (
151
+ is_omniroute_referer
152
+ or any(req_path == p or req_path.startswith(p) for p in OMNIROUTE_PREFIXES)
153
  or req_path in OMNIROUTE_EXACT
154
  ):
155
+ if not (req_path.startswith("/jellyfin") or req_path.startswith("/tg-stream") or req_path.startswith("/tg_stream") or req_path == "/health/live"):
156
+ logger.info(f"[ROUTER] {req_path} (referer={referer}) -> OmniRoute ({OMNIROUTE_PORT})")
157
+ return await proxy_http_request(f"http://127.0.0.1:{OMNIROUTE_PORT}{req_path}", request, default_prefix="", extra_headers=extra)
 
 
 
 
 
158
 
159
  # ── 2. Jellyfin Media Server Namespace ────────────────────────────────────
160
  if req_path == "/jellyfin" or req_path.startswith("/jellyfin/"):