Skip to content

Commit

Permalink
#1399[FIX] file server in subdomain with request path "/"
Browse files Browse the repository at this point in the history
Former-commit-id: de4326943640706a9a2f1418327c4a69bc5f85d9
  • Loading branch information
minhvh committed Dec 3, 2019
1 parent 6dcbbc5 commit 137fa92
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion core/router/api_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,11 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio
continue
}

requestPath := s.RequestPath[strings.Index(s.RequestPath, api.relativePath)+len(api.relativePath):]
slashIdx := strings.IndexByte(s.RequestPath, '/')
if slashIdx == -1 {
slashIdx = 0
}
requestPath = s.RequestPath[slashIdx:]
routes = append(routes, api.createRoutes([]string{http.MethodGet}, requestPath, h)...)
getRoute.StaticSites = append(getRoute.StaticSites, s)
}
Expand Down
2 changes: 1 addition & 1 deletion core/router/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri

splitPath := strings.Split(s, ".")
if len(splitPath) == 2 && splitPath[1] == "" {
return splitPath[0], "/"
return splitPath[0] + ".", "/"
}

slashIdx := strings.IndexByte(s, '/')
Expand Down
4 changes: 2 additions & 2 deletions core/router/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func TestSplitSubdomainAndPath(t *testing.T) {
path string
}{
{"admin./users/42", "admin.", "/users/42"},
{"admin.", "admin", "/"},
{"admin./" + WildcardFileParam(), "admin.", "/" + WildcardFileParam()},
{"static.", "static.", "/"},
{"static./" + WildcardFileParam(), "static.", "/" + WildcardFileParam()},
{"//api/users\\42", "", "/api/users/42"},
{"admin./users//42", "admin.", "/users/42"},
{"*./users/42/", "*.", "/users/42"},
Expand Down

0 comments on commit 137fa92

Please sign in to comment.