mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-18 15:13:32 -05:00
31 lines
579 B
Go
31 lines
579 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Static is a middleware that serves static assets.
|
|
func Static(fs http.FileSystem) func(http.Handler) http.Handler {
|
|
static := http.StripPrefix(
|
|
"/",
|
|
http.FileServer(
|
|
fs,
|
|
),
|
|
)
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if strings.HasPrefix(r.URL.Path, "/api") {
|
|
next.ServeHTTP(w, r)
|
|
} else {
|
|
if strings.HasSuffix(r.URL.Path, "/") {
|
|
http.NotFound(w, r)
|
|
} else {
|
|
static.ServeHTTP(w, r)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|