From 423164a668efda899d8690b0f8cfed1caed62929 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Thu, 3 Feb 2022 17:09:14 +0100 Subject: [PATCH] simplify fileserver path cleaning fix typo --- changelog/unreleased/enhancement-web-spa-fileserver.md | 2 +- web/pkg/assets/server.go | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/changelog/unreleased/enhancement-web-spa-fileserver.md b/changelog/unreleased/enhancement-web-spa-fileserver.md index 0f20a129b2a..dad95f59eec 100644 --- a/changelog/unreleased/enhancement-web-spa-fileserver.md +++ b/changelog/unreleased/enhancement-web-spa-fileserver.md @@ -1,4 +1,4 @@ -Enhancement: Add SPA conform fileserver fow web +Enhancement: Add SPA conform fileserver for web We've added an SPA conform fileserver to the web service. It enables web to use vue's history mode and behaves like nginx try_files. diff --git a/web/pkg/assets/server.go b/web/pkg/assets/server.go index 4b6ed19ad84..527134330c8 100644 --- a/web/pkg/assets/server.go +++ b/web/pkg/assets/server.go @@ -8,7 +8,6 @@ import ( "net/http" "path" "path/filepath" - "strings" ) type fileServer struct { @@ -20,12 +19,8 @@ func FileServer(root http.FileSystem) http.Handler { } func (f *fileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { - upath := r.URL.Path - if !strings.HasPrefix(upath, "/") { - upath = "/" + upath - r.URL.Path = upath - } - upath = path.Clean(upath) + upath := path.Clean(path.Join("/", r.URL.Path)) + r.URL.Path = upath asset, err := f.root.Open(upath) if err != nil {