From 84a2cb246c5c6172c2499f57a43cbc898d4e2c3f Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 25 Jan 2025 11:29:39 -0500 Subject: make simpleapp helm template Signed-off-by: Xe Iaso --- cmd/httpdebug/main.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'cmd/httpdebug/main.go') diff --git a/cmd/httpdebug/main.go b/cmd/httpdebug/main.go index 1f7a042..8162bc2 100644 --- a/cmd/httpdebug/main.go +++ b/cmd/httpdebug/main.go @@ -8,6 +8,7 @@ import ( "log/slog" "net/http" "os" + "strings" "within.website/x/internal" ) @@ -19,12 +20,28 @@ var ( func main() { internal.HandleStartup() + mux := http.NewServeMux() + + mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "OK") + }) + + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + contains := strings.Contains(r.Header.Get("Accept"), "text/html") + + if contains { + w.Header().Add("Content-Type", "text/html") + fmt.Fprint(w, "
")
+		}
+
+		fmt.Println("---")
+		r.Write(io.MultiWriter(w, os.Stdout))
+
+		if contains {
+			fmt.Fprintln(w, "
") + } + }) + slog.Info("listening", "url", "http://localhost"+*bind) - log.Fatal(http.ListenAndServe(*bind, http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { - fmt.Println("---") - r.Write(io.MultiWriter(w, os.Stdout)) - fmt.Println("---") - }, - ))) + log.Fatal(http.ListenAndServe(*bind, mux)) } -- cgit v1.2.3