Rename API endpoints to /tendrils/api/*, detect SSE via Accept header

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-30 22:31:58 -08:00
parent 98c7fc75b7
commit d63b8192d2
4 changed files with 10 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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() {

View File

@@ -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() {