From 0f5a6c5e12aa10779d41eb67394645bad3aabb13 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 3 Oct 2024 23:27:10 +0200 Subject: Add "Site not found" functionality --- main.go | 11 ++++++++++- templ/404.tpl | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 templ/404.tpl diff --git a/main.go b/main.go index 1886736..84dcd6e 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ func main() { mux := http.NewServeMux() + // handlers that DO NOT require authentification mux.Handle("GET /login", loginPage()) mux.HandleFunc("POST /login", handleLogin) mux.Handle("GET /logout", handleLogout()) @@ -57,11 +58,13 @@ func main() { handler = handlers.CombinedLoggingHandler(os.Stderr, handler) handler = handlers.ProxyHeaders(handler) - // the real content, needing authentification + // setup authentification authMux := http.NewServeMux() mux.Handle("/", RequireAuth(authMux)) + // handlers that required authentification authMux.Handle("GET /{$}", indexPage()) + authMux.Handle("GET /", notfound()) log.Fatal(http.ListenAndServe(os.Getenv("GOSTEN_ADDRESS"), handler)) } @@ -79,3 +82,9 @@ func indexPage() http.HandlerFunc { showTemplate(w, "index", u.Name) } } + +func notfound() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + showTemplate(w, "404", r.RequestURI) + } +} diff --git a/templ/404.tpl b/templ/404.tpl new file mode 100644 index 0000000..b0a3658 --- /dev/null +++ b/templ/404.tpl @@ -0,0 +1,10 @@ +{{define "main"}} + +{{end}} \ No newline at end of file -- cgit v1.2.3-70-g09d2