mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-20 13:59:21 -04:00
Merge pull request #10 from owncloud/static-root-path
Add root path to static middleware
This commit is contained in:
7
changelog/unreleased/static-root-path.md
Normal file
7
changelog/unreleased/static-root-path.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Change: Add root path to static middleware
|
||||
|
||||
Currently the `Static` middleware always serves from the root path, but all our
|
||||
HTTP handlers accept a custom root path which also got to be applied to the
|
||||
static file handling.
|
||||
|
||||
https://github.com/owncloud/ocis-pkg/issues/9
|
||||
@@ -2,13 +2,14 @@ package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Static is a middleware that serves static assets.
|
||||
func Static(fs http.FileSystem) func(http.Handler) http.Handler {
|
||||
func Static(root string, fs http.FileSystem) func(http.Handler) http.Handler {
|
||||
static := http.StripPrefix(
|
||||
"/",
|
||||
root+"/",
|
||||
http.FileServer(
|
||||
fs,
|
||||
),
|
||||
@@ -16,7 +17,7 @@ func Static(fs http.FileSystem) func(http.Handler) http.Handler {
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.URL.Path, "/api") {
|
||||
if strings.HasPrefix(r.URL.Path, path.Join(root, "api")) {
|
||||
next.ServeHTTP(w, r)
|
||||
} else {
|
||||
if strings.HasSuffix(r.URL.Path, "/") {
|
||||
|
||||
Reference in New Issue
Block a user