Hermes Agent commited on
Commit
47c9771
·
1 Parent(s): 1acaca8

Capture omniroute serve output to /data/omniroute/omniroute.log and expose full stack trace/logs to Browser Inspect DevTools console & HTML UI on 500 error

Browse files
Files changed (2) hide show
  1. entrypoint.sh +2 -2
  2. gateway/omniroute.py +43 -9
entrypoint.sh CHANGED
@@ -113,8 +113,8 @@ print('[INIT] Wrote pristine OmniRoute .env config files.')
113
  " 2>/dev/null || true
114
 
115
  omniroute runtime repair 2>&1 || true
116
- omniroute serve --port 20128 --no-open &
117
- echo "[INIT] OmniRoute started in background with required secrets, HOSTNAME un-set, and runtime repair."
118
  else
119
  echo "[WARN] omniroute binary not found, skipping background service."
120
  fi
 
113
  " 2>/dev/null || true
114
 
115
  omniroute runtime repair 2>&1 || true
116
+ omniroute serve --port 20128 --no-open > /data/omniroute/omniroute.log 2>&1 &
117
+ echo "[INIT] OmniRoute started in background with required secrets, HOSTNAME un-set, and logging to /data/omniroute/omniroute.log."
118
  else
119
  echo "[WARN] omniroute binary not found, skipping background service."
120
  fi
gateway/omniroute.py CHANGED
@@ -114,15 +114,49 @@ async def omniroute_main_route(request: Request, path: str = ""):
114
  if location.rstrip("/") in ("/omniroute", f"https://{OMNIROUTE_PORT}", "http://127.0.0.1:20128", "/"):
115
  return RedirectResponse("/omniroute/dashboard", status_code=302)
116
 
117
- # If status is 404 or 500, try with /omniroute/ subpath prefix on upstream
118
- if res.status_code in (404, 500):
119
- alt_target = f"http://127.0.0.1:{OMNIROUTE_PORT}/omniroute/{path}"
120
- try:
121
- alt_res = await proxy_http_request(alt_target, request, default_prefix="/omniroute", extra_headers=extra, html_fixup=fixup_omniroute_html)
122
- if alt_res.status_code not in (404, 500):
123
- return alt_res
124
- except Exception:
125
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  return res
128
 
 
114
  if location.rstrip("/") in ("/omniroute", f"https://{OMNIROUTE_PORT}", "http://127.0.0.1:20128", "/"):
115
  return RedirectResponse("/omniroute/dashboard", status_code=302)
116
 
117
+ # If status is 500 on GET, capture OmniRoute server log file and expose to Browser DevTools Console & UI
118
+ if res.status_code == 500 and request.method == "GET":
119
+ log_content = ""
120
+ for log_file in ["/data/omniroute/omniroute.log", "/root/.omniroute/omniroute.log"]:
121
+ try:
122
+ import os
123
+ if os.path.exists(log_file):
124
+ with open(log_file, "r", encoding="utf-8", errors="ignore") as f:
125
+ lines = f.readlines()
126
+ log_content = "".join(lines[-120:])
127
+ if log_content:
128
+ break
129
+ except Exception:
130
+ pass
131
+
132
+ if log_content:
133
+ print(f"[OMNIROUTE 500 DIAGNOSTIC LOGS]\n{log_content}")
134
+ safe_logs = log_content.replace("\\", "\\\\").replace("`", "\\`").replace("$", "\\$")
135
+ diagnostic_html = f"""<!DOCTYPE html>
136
+ <html>
137
+ <head>
138
+ <title>OmniRoute Server Error Diagnostic</title>
139
+ <style>
140
+ body {{ font-family: system-ui, monospace; background: #0f172a; color: #f8fafc; padding: 24px; max-width: 1000px; margin: 0 auto; }}
141
+ h1 {{ color: #f87171; font-size: 1.4rem; margin-top: 0; }}
142
+ p {{ color: #94a3b8; font-size: 0.95rem; }}
143
+ pre {{ background: #1e293b; padding: 16px; border-radius: 8px; overflow-x: auto; color: #38bdf8; border: 1px solid #334155; font-size: 0.85rem; line-height: 1.5; }}
144
+ </style>
145
+ <script>
146
+ console.error("=== OMNIROUTE BACKEND 500 DIAGNOSTIC LOGS ===");
147
+ console.error(`{safe_logs}`);
148
+ console.group("OmniRoute Backend Server Logs");
149
+ console.log(`{safe_logs}`);
150
+ console.groupEnd();
151
+ </script>
152
+ </head>
153
+ <body>
154
+ <h1>⚠️ OmniRoute Server Diagnostic (HTTP 500)</h1>
155
+ <p>Captured backend process logs for route <code>/{path}</code>. Logs have also been printed to <strong>Browser Inspect → Console</strong>:</p>
156
+ <pre>{log_content}</pre>
157
+ </body>
158
+ </html>"""
159
+ return HTMLResponse(content=diagnostic_html, status_code=500)
160
 
161
  return res
162