Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
61 lines
919 B
Go
61 lines
919 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func NormalizePath(
|
|
next http.Handler,
|
|
) http.Handler {
|
|
|
|
return http.HandlerFunc(
|
|
func(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
p := r.URL.Path
|
|
// Hosted adapter assets use directory-relative module and worker URLs.
|
|
// DAV collections also require the slash: removing it conflicts with
|
|
// ServeMux's collection redirect and causes an infinite redirect loop.
|
|
if strings.HasPrefix(p, "/_/adaptor/") || strings.HasPrefix(p, "/_/api/v1/caldav/") {
|
|
next.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
|
|
if p != "/" {
|
|
|
|
for strings.HasSuffix(
|
|
p,
|
|
"/",
|
|
) {
|
|
|
|
p = strings.TrimSuffix(
|
|
p,
|
|
"/",
|
|
)
|
|
}
|
|
|
|
if p == "" {
|
|
p = "/"
|
|
}
|
|
|
|
if p != r.URL.Path {
|
|
|
|
http.Redirect(
|
|
w,
|
|
r,
|
|
p,
|
|
http.StatusMovedPermanently,
|
|
)
|
|
|
|
return
|
|
}
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
},
|
|
)
|
|
}
|