Add healthcheck route

This commit is contained in:
Owen
2025-12-12 11:47:04 -05:00
parent 9e140a94db
commit 82256a3f6f

10
main.go
View File

@@ -382,6 +382,7 @@ func main() {
http.HandleFunc("/update-proxy-mapping", handleUpdateProxyMapping) http.HandleFunc("/update-proxy-mapping", handleUpdateProxyMapping)
http.HandleFunc("/update-destinations", handleUpdateDestinations) http.HandleFunc("/update-destinations", handleUpdateDestinations)
http.HandleFunc("/update-local-snis", handleUpdateLocalSNIs) http.HandleFunc("/update-local-snis", handleUpdateLocalSNIs)
http.HandleFunc("/healthz", handleHealthz)
logger.Info("Starting HTTP server on %s", listenAddr) logger.Info("Starting HTTP server on %s", listenAddr)
// HTTP server with graceful shutdown on context cancel // HTTP server with graceful shutdown on context cancel
@@ -833,6 +834,15 @@ func handlePeer(w http.ResponseWriter, r *http.Request) {
} }
} }
func handleHealthz(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}
func handleAddPeer(w http.ResponseWriter, r *http.Request) { func handleAddPeer(w http.ResponseWriter, r *http.Request) {
var peer Peer var peer Peer
if err := json.NewDecoder(r.Body).Decode(&peer); err != nil { if err := json.NewDecoder(r.Body).Decode(&peer); err != nil {