summaryrefslogtreecommitdiff
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
parent9a7b63bbc3cbce5ac469daf426da08a69c59bed4 (diff)
add permanent redirects for endpoints
-rw-r--r--main.go17
-rw-r--r--page/default.go4
-rw-r--r--proxy.go5
3 files changed, 24 insertions, 2 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)
diff --git a/page/default.go b/page/default.go
index ea51acc..d13689b 100644
--- a/page/default.go
+++ b/page/default.go
@@ -82,7 +82,7 @@ func DefaultError404() (string, error) {
func DefaultError500() (string, error) {
return buildPage(page{
- Title: "500 Not Found",
- Body: "<h1>Error 500: Page not found</h1>",
+ Title: "500 Internal Server Error",
+ Body: "<h1>Error 500: Internal server error</h1>",
})
}
diff --git a/proxy.go b/proxy.go
index 7be9419..4442fb9 100644
--- a/proxy.go
+++ b/proxy.go
@@ -31,6 +31,11 @@ func addEndpoint(s *auth.Sessions, pages page.Pages, e config.Endpoint) {
Origin: origin,
}
+ http.HandleFunc(e.Path, func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Add("Location", e.Path + "/")
+ w.WriteHeader(http.StatusPermanentRedirect)
+ })
+
http.HandleFunc(e.Path + "/", func(w http.ResponseWriter, r *http.Request) {
log.Infof("REQ: %v", r.URL.Path)
proxy(w, r, s, pages, end)