From a2f7fd3070513941dded47a7ceb8afce75f337ce Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 14 May 2023 22:24:58 -0500 Subject: add permanent redirects for endpoints --- main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index f9ae240..37c0fdc 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "fmt" "flag" "errors" + "strings" + "path/filepath" "net/http" "encoding/json" "sanine.net/git/phlox/config" @@ -30,6 +32,21 @@ func main() { Logout(w, r, sessions) }) + http.HandleFunc("/phlox/asset/", func(w http.ResponseWriter, r *http.Request) { + filename := strings.TrimPrefix(r.URL.Path, "/phlox/asset/") + path := filepath.Join(conf.AssetDirectory, filename) + http.ServeFile(w, r, path) + }) + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" { + w.Header().Add("Location", "/phlox/login") + w.WriteHeader(http.StatusTemporaryRedirect) + } else { + pages.ServeError404(w) + } + }) + // add reverse proxy endpoints for _, e := range conf.Endpoints { addEndpoint(sessions, pages, e) -- cgit v1.2.1