Skip to content

Commit 1f3d651

Browse files
committed
fix(serverHandler/wsl1): strip alias URL prefix when serving content
1 parent 7f7a76b commit 1f3d651

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/serverHandler/aliasHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
var defaultHandler = http.NotFoundHandler()
1515

16-
var createFileServer func(root string) http.Handler
16+
var createFileServer func(aliasUrl, aliasFs string) http.Handler
1717

1818
type pathStrings struct {
1919
path string
@@ -219,7 +219,7 @@ func newAliasHandler(
219219

220220
var fileServer http.Handler
221221
if !emptyRoot && createFileServer != nil { // for WSL 1 fix
222-
fileServer = createFileServer(currentAlias.fs)
222+
fileServer = createFileServer(currentAlias.url, currentAlias.fs)
223223
}
224224

225225
h := &aliasHandler{

src/serverHandler/wsl1.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ func (fs wrappedHttpFileSystem) Open(name string) (http.File, error) {
2323
return wrappedHttpFile{file}, err
2424
}
2525

26-
func createFsFileServer(root string) http.Handler {
27-
return http.FileServer(wrappedHttpFileSystem{http.Dir(root)})
26+
func createFsFileServer(aliasUrl, aliasFs string) http.Handler {
27+
fs := wrappedHttpFileSystem{http.Dir(aliasFs)}
28+
handler := http.FileServer(fs)
29+
handler = http.StripPrefix(aliasUrl, handler)
30+
return handler
2831
}
2932

3033
func serveFsContent(h *aliasHandler, w http.ResponseWriter, r *http.Request, info os.FileInfo, file *os.File) {

0 commit comments

Comments
 (0)