diff options
author | sanine <sanine.not@pm.me> | 2023-05-14 22:24:58 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-14 22:24:58 -0500 |
commit | a2f7fd3070513941dded47a7ceb8afce75f337ce (patch) | |
tree | f84e71c6b0664bc1ad57743926f28da2511c948c /main.go | |
parent | 9a7b63bbc3cbce5ac469daf426da08a69c59bed4 (diff) |
add permanent redirects for endpoints
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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) |