update
This commit is contained in:
+19
-4
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.tornberg.me/go-otel/internal/collector"
|
||||
"git.tornberg.me/go-otel/internal/websocket"
|
||||
@@ -150,10 +151,9 @@ func main() {
|
||||
|
||||
// WebSocket server for visualization
|
||||
http.HandleFunc("/ws", wsServer.HandleConnections)
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("OTel Debug Receiver is running"))
|
||||
})
|
||||
|
||||
// Serve static files with SPA fallback
|
||||
http.Handle("/", spaHandler(http.Dir("./dist")))
|
||||
|
||||
log.Printf("Starting HTTP server on port 8080")
|
||||
log.Printf("OTLP HTTP endpoints:")
|
||||
@@ -345,3 +345,18 @@ func handleHistoryByType(coll *collector.Collector, dataType string) http.Handle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func spaHandler(root http.FileSystem) http.Handler {
|
||||
fileServer := http.FileServer(root)
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.URL.Path
|
||||
// Skip API, WebSocket, and OTLP endpoints
|
||||
if !strings.HasPrefix(path, "/api") && !strings.HasPrefix(path, "/ws") && !strings.HasPrefix(path, "/v1") {
|
||||
if _, err := root.Open(path); err != nil {
|
||||
// File does not exist, serve index.html
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
}
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user