From 9fd3077cae927093942bb5da29abb9a9e0fcca1b Mon Sep 17 00:00:00 2001 From: pnannery Date: Fri, 11 Sep 2026 08:37:25 -0400 Subject: [PATCH] fix: redirect browser visits from API state to dashboard --- dashboard.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dashboard.py b/dashboard.py index 58b90d9..4c097a3 100644 --- a/dashboard.py +++ b/dashboard.py @@ -52,7 +52,14 @@ class H(BaseHTTPRequestHandler): p=urlparse(self.path).path if p=='/':return self.send(200,INDEX,'text/html; charset=utf-8') if p=='/api/watchlist':return self.send(200,json.dumps(watchlist.read())) - if p=='/api/state':return self.send(200,STATE.read_text() if STATE.exists() else '{}') + if p=='/api/state': + # If someone opens the JSON endpoint directly from a phone/browser, + # send them to the dashboard instead of a raw JSON wall. Programmatic + # callers and dashboard fetch() still receive JSON. + accept=self.headers.get('Accept','') + if 'text/html' in accept and 'application/json' not in accept: + self.send_response(303);self.send_header('Location','/');self.send_header('Cache-Control','no-store');self.end_headers();return + return self.send(200,STATE.read_text() if STATE.exists() else '{}') if p=='/api/report':return self.send(200,report_text(json.loads(STATE.read_text()) if STATE.exists() else {}),'text/plain; charset=utf-8') if p=='/api/log': from collections import deque