feat: make server options a struct (#615)

Former-commit-id: a54bc7c8a0fb700d4f90f78c54d6cb028e8acea7 [formerly a0946a1d5b82ce5681684bc0f871bd892c4d6c3f] [formerly 6b23b0abbe5cde6a6348f982975d15a1161359de [formerly 0e7abaa7fb4b293e933d233750cf057c48b298bf]]
Former-commit-id: cf9ea1110bcb8b5eb30ecd25db1928659ecea922 [formerly 38cebeff1f9e6b03760f7b277a3941f7bd733fb5]
Former-commit-id: db44c1d5ff8fed361849b5bf1fe48e04c75d7ce7
This commit is contained in:
Henrique Dias
2019-01-08 10:29:09 +00:00
committed by GitHub
parent 802318f903
commit 01929c72ea
13 changed files with 159 additions and 90 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/GeertJohan/go.rice"
"github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/storage"
"github.com/filebrowser/filebrowser/v2/version"
)
@@ -18,12 +19,12 @@ import (
func handleWithStaticData(w http.ResponseWriter, r *http.Request, d *data, box *rice.Box, file, contentType string) (int, error) {
w.Header().Set("Content-Type", contentType)
staticURL := strings.TrimPrefix(d.settings.BaseURL+"/static", "/")
staticURL := strings.TrimPrefix(d.server.BaseURL+"/static", "/")
data := map[string]interface{}{
"Name": d.settings.Branding.Name,
"DisableExternal": d.settings.Branding.DisableExternal,
"BaseURL": d.settings.BaseURL,
"BaseURL": d.server.BaseURL,
"Version": version.Version,
"StaticURL": staticURL,
"Signup": d.settings.Signup,
@@ -76,7 +77,7 @@ func handleWithStaticData(w http.ResponseWriter, r *http.Request, d *data, box *
return 0, nil
}
func getStaticHandlers(storage *storage.Storage) (http.Handler, http.Handler) {
func getStaticHandlers(storage *storage.Storage, server *settings.Server) (http.Handler, http.Handler) {
box := rice.MustFindBox("../frontend/dist")
handler := http.FileServer(box.HTTPBox())
@@ -87,7 +88,7 @@ func getStaticHandlers(storage *storage.Storage) (http.Handler, http.Handler) {
w.Header().Set("x-xss-protection", "1; mode=block")
return handleWithStaticData(w, r, d, box, "index.html", "text/html; charset=utf-8")
}, "", storage)
}, "", storage, server)
static := handle(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
if r.Method != http.MethodGet {
@@ -113,7 +114,7 @@ func getStaticHandlers(storage *storage.Storage) (http.Handler, http.Handler) {
}
return handleWithStaticData(w, r, d, box, r.URL.Path, "application/javascript; charset=utf-8")
}, "/static/", storage)
}, "/static/", storage, server)
return index, static
}