diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-03 23:27:10 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-03 23:27:10 +0200 |
commit | 0f5a6c5e12aa10779d41eb67394645bad3aabb13 (patch) | |
tree | ba0d62b92e395ebcc1b61f44fa945762ad672477 | |
parent | b731258e18504ce41ba96ff890c96a385e7a3347 (diff) | |
download | gosten-0f5a6c5e12aa10779d41eb67394645bad3aabb13.tar.gz gosten-0f5a6c5e12aa10779d41eb67394645bad3aabb13.tar.bz2 gosten-0f5a6c5e12aa10779d41eb67394645bad3aabb13.zip |
Add "Site not found" functionality
Diffstat (limited to '')
-rw-r--r-- | main.go | 11 | ||||
-rw-r--r-- | templ/404.tpl | 10 |
2 files changed, 20 insertions, 1 deletions
@@ -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"}} + <div class="alert alert-danger d-flex align-items-center" role="alert"> + <svg class="me-2" role="img" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"> + <path d="M9.05.435c-.58-.58-1.52-.58-2.1 0L.436 6.95c-.58.58-.58 1.519 0 2.098l6.516 6.516c.58.58 1.519.58 2.098 0l6.516-6.516c.58-.58.58-1.519 0-2.098zM8 4c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995A.905.905 0 0 1 8 4m.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2"/> + </svg> + <div> + Seite <span class="fst-italic">{{.}}</span> nicht gefunden! + </div> + </div> +{{end}}
\ No newline at end of file |