summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-14 22:24:58 -0500
committersanine <sanine.not@pm.me>2023-05-14 22:24:58 -0500
commita2f7fd3070513941dded47a7ceb8afce75f337ce (patch)
treef84e71c6b0664bc1ad57743926f28da2511c948c /main.go
parent9a7b63bbc3cbce5ac469daf426da08a69c59bed4 (diff)
add permanent redirects for endpoints
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 17 insertions, 0 deletions
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)