diff --git a/http.go b/http.go index 596c4c7..be42ffb 100644 --- a/http.go +++ b/http.go @@ -2,8 +2,10 @@ package main import ( "context" + _ "embed" "fmt" "net/http" + "os" ) type Context struct { @@ -12,6 +14,12 @@ type Context struct { func HTTP(port int, db DB) error { foo := func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/": + httpRoot(w, r) + default: + http.NotFound(w, r) + } } foo = withAuth(foo) return http.ListenAndServe(fmt.Sprintf(":%d", port), http.HandlerFunc(foo)) @@ -41,3 +49,15 @@ func withAuth(foo http.HandlerFunc) http.HandlerFunc { foo(w, r) } } + +//go:embed public/root.html +var httpRootHTML string + +func httpRoot(w http.ResponseWriter, r *http.Request) { + body := httpRootHTML + if os.Getenv("DEBUG") { + b, _ := os.ReadFile("public/root.html") + body = string(b) + } + w.Write([]byte(body)) +} diff --git a/public/root.html b/public/root.html new file mode 100644 index 0000000..45b983b --- /dev/null +++ b/public/root.html @@ -0,0 +1 @@ +hi