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:
@@ -50,7 +50,7 @@ type artmapToAddr struct {
|
|||||||
var artmapClient = &http.Client{Timeout: 2 * time.Second}
|
var artmapClient = &http.Client{Timeout: 2 * time.Second}
|
||||||
|
|
||||||
func (t *Tendrils) probeArtmap(ip net.IP) {
|
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)
|
resp, err := artmapClient.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
9
http.go
9
http.go
@@ -47,9 +47,8 @@ func (t *Tendrils) startHTTPServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/api/status", t.handleAPIStatus)
|
mux.HandleFunc("/tendrils/api/status", t.handleAPIStatus)
|
||||||
mux.HandleFunc("/api/status/stream", t.handleAPIStatusStream)
|
mux.HandleFunc("/tendrils/api/errors/clear", t.handleClearError)
|
||||||
mux.HandleFunc("/api/errors/clear", t.handleClearError)
|
|
||||||
mux.Handle("/", noCacheHandler(http.FileServer(http.Dir("static"))))
|
mux.Handle("/", noCacheHandler(http.FileServer(http.Dir("static"))))
|
||||||
|
|
||||||
log.Printf("[https] listening on :443")
|
log.Printf("[https] listening on :443")
|
||||||
@@ -122,6 +121,10 @@ func ensureCert() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tendrils) handleAPIStatus(w http.ResponseWriter, r *http.Request) {
|
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")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
data, err := t.GetStatusJSON()
|
data, err := t.GetStatusJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
let currentConfig = null;
|
let currentConfig = null;
|
||||||
|
|
||||||
function connectSSE() {
|
function connectSSE() {
|
||||||
const evtSource = new EventSource('/api/status/stream');
|
const evtSource = new EventSource('/tendrils/api/status');
|
||||||
let heartbeatTimeout = null;
|
let heartbeatTimeout = null;
|
||||||
|
|
||||||
function resetHeartbeat() {
|
function resetHeartbeat() {
|
||||||
|
|||||||
@@ -135,11 +135,11 @@ export function scrollToNode(typeid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function clearError(id) {
|
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() {
|
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() {
|
export function updateErrorPanel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user