aboutsummaryrefslogtreecommitdiff
path: root/cmd/httpdebug
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/httpdebug')
-rw-r--r--cmd/httpdebug/main.go31
1 files changed, 24 insertions, 7 deletions
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, "<pre id=\"main\"><code>")
+ }
+
+ fmt.Println("---")
+ r.Write(io.MultiWriter(w, os.Stdout))
+
+ if contains {
+ fmt.Fprintln(w, "</pre></code>")
+ }
+ })
+
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))
}