From fa8e1ee0337fd5d712e8b6d94b3628ab00c1ef50 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Wed, 27 May 2020 23:58:57 +0100 Subject: [PATCH] Allow file server to handle windows filesystems --- pkg/upstream/file.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/upstream/file.go b/pkg/upstream/file.go index ec7492c5..7f67edb0 100644 --- a/pkg/upstream/file.go +++ b/pkg/upstream/file.go @@ -1,6 +1,10 @@ package upstream -import "net/http" +import ( + "net/http" + "runtime" + "strings" +) const fileScheme = "file" @@ -15,6 +19,12 @@ func newFileServer(id, path, fileSystemPath string) http.Handler { // newFileServerForPath creates a http.Handler to serve files from the filesystem func newFileServerForPath(path string, filesystemPath string) http.Handler { + // Windows fileSSystemPath will be be prefixed with `/`, eg`/C:/..., + // if they were parsed by url.Parse` + if runtime.GOOS == "windows" { + filesystemPath = strings.TrimPrefix(filesystemPath, "/") + } + return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath))) }