From d63b8192d274aaf5154ef195907b0d4ddd58ccfe Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 30 Jan 2026 22:31:58 -0800 Subject: [PATCH] Rename API endpoints to /tendrils/api/*, detect SSE via Accept header Co-Authored-By: Claude Opus 4.5 --- artmap.go | 2 +- http.go | 9 ++++++--- static/js/app.js | 2 +- static/js/ui.js | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/artmap.go b/artmap.go index 793464f..f638424 100644 --- a/artmap.go +++ b/artmap.go @@ -50,7 +50,7 @@ type artmapToAddr struct { var artmapClient = &http.Client{Timeout: 2 * time.Second} func (t *Tendrils) probeArtmap(ip net.IP) { - url := fmt.Sprintf("http://%s:8080/api/config", ip) + url := fmt.Sprintf("http://%s:8080/artmap/api/status", ip) resp, err := artmapClient.Get(url) if err != nil { diff --git a/http.go b/http.go index fb011e0..8eb4e83 100644 --- a/http.go +++ b/http.go @@ -47,9 +47,8 @@ func (t *Tendrils) startHTTPServer() { } mux := http.NewServeMux() - mux.HandleFunc("/api/status", t.handleAPIStatus) - mux.HandleFunc("/api/status/stream", t.handleAPIStatusStream) - mux.HandleFunc("/api/errors/clear", t.handleClearError) + mux.HandleFunc("/tendrils/api/status", t.handleAPIStatus) + mux.HandleFunc("/tendrils/api/errors/clear", t.handleClearError) mux.Handle("/", noCacheHandler(http.FileServer(http.Dir("static")))) log.Printf("[https] listening on :443") @@ -122,6 +121,10 @@ func ensureCert() error { } func (t *Tendrils) handleAPIStatus(w http.ResponseWriter, r *http.Request) { + if r.Header.Get("Accept") == "text/event-stream" { + t.handleAPIStatusStream(w, r) + return + } w.Header().Set("Content-Type", "application/json; charset=utf-8") data, err := t.GetStatusJSON() if err != nil { diff --git a/static/js/app.js b/static/js/app.js index 4d3ccc3..3aa944a 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -10,7 +10,7 @@ import { let currentConfig = null; function connectSSE() { - const evtSource = new EventSource('/api/status/stream'); + const evtSource = new EventSource('/tendrils/api/status'); let heartbeatTimeout = null; function resetHeartbeat() { diff --git a/static/js/ui.js b/static/js/ui.js index 34b5d9b..31b026d 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -135,11 +135,11 @@ export function scrollToNode(typeid) { } export async function clearError(id) { - await fetch('/api/errors/clear?id=' + encodeURIComponent(id), { method: 'POST' }); + await fetch('/tendrils/api/errors/clear?id=' + encodeURIComponent(id), { method: 'POST' }); } export async function clearAllErrors() { - await fetch('/api/errors/clear?all=true', { method: 'POST' }); + await fetch('/tendrils/api/errors/clear?all=true', { method: 'POST' }); } export function updateErrorPanel() {