http root serves public/root.html
parent
a8b5942833
commit
933f87d11d
20
http.go
20
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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
hi
|
||||
Loading…
Reference in New Issue