Skip to content

Commit 0c40389

Browse files
authored
Merge pull request #1400 from minhvh93/master
#1399 [BUG]Can't set file server in subdomain with request path is "/" Former-commit-id: 3710e0f3a01a8d297de7161e4793c258ab8f05ba
2 parents 4e9a6be + 137fa92 commit 0c40389

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

core/router/api_builder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,11 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio
488488
continue
489489
}
490490

491-
requestPath := s.RequestPath[strings.Index(s.RequestPath, api.relativePath)+len(api.relativePath):]
491+
slashIdx := strings.IndexByte(s.RequestPath, '/')
492+
if slashIdx == -1 {
493+
slashIdx = 0
494+
}
495+
requestPath = s.RequestPath[slashIdx:]
492496
routes = append(routes, api.createRoutes([]string{http.MethodGet}, requestPath, h)...)
493497
getRoute.StaticSites = append(getRoute.StaticSites, s)
494498
}

core/router/path.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri
231231
return "", "/"
232232
}
233233

234+
splitPath := strings.Split(s, ".")
235+
if len(splitPath) == 2 && splitPath[1] == "" {
236+
return splitPath[0] + ".", "/"
237+
}
238+
234239
slashIdx := strings.IndexByte(s, '/')
235240
if slashIdx > 0 {
236241
// has subdomain

core/router/path_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ func TestSplitSubdomainAndPath(t *testing.T) {
116116
path string
117117
}{
118118
{"admin./users/42", "admin.", "/users/42"},
119+
{"static.", "static.", "/"},
120+
{"static./" + WildcardFileParam(), "static.", "/" + WildcardFileParam()},
119121
{"//api/users\\42", "", "/api/users/42"},
120122
{"admin./users//42", "admin.", "/users/42"},
121123
{"*./users/42/", "*.", "/users/42"},

middleware/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ Builtin Handlers
44
| Middleware | Example |
55
| -----------|-------------|
66
| [basic authentication](basicauth) | [iris/_examples/authentication/basicauth](https://github.com/kataras/iris/tree/master/_examples/authentication/basicauth) |
7-
| [Google reCAPTCHA](recaptcha) | [iris/_examples/miscellaneous/recaptcha](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recaptcha) |
87
| [localization and internationalization](i18n) | [iris/_examples/miscellaneous/i81n](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n) |
98
| [request logger](logger) | [iris/_examples/http_request/request-logger](https://github.com/kataras/iris/tree/master/_examples/http_request/request-logger) |
9+
| [HTTP method override](methodoverride) | [iris/middleware/methodoverride/methodoverride_test.go](https://github.com/kataras/iris/blob/master/middleware/methodoverride/methodoverride_test.go) |
1010
| [profiling (pprof)](pprof) | [iris/_examples/miscellaneous/pprof](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/pprof) |
11+
| [Google reCAPTCHA](recaptcha) | [iris/_examples/miscellaneous/recaptcha](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recaptcha) |
1112
| [recovery](recover) | [iris/_examples/miscellaneous/recover](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recover) |
1213

13-
Experimental Handlers
14+
Community made
1415
------------
1516

1617
Most of the experimental handlers are ported to work with _iris_'s handler form, from third-party sources.
@@ -30,7 +31,7 @@ Most of the experimental handlers are ported to work with _iris_'s handler form,
3031
Third-Party Handlers
3132
------------
3233

33-
iris has its own middleware form of `func(ctx context.Context)` but it's also compatible with all `net/http` middleware forms. See [here](https://github.com/kataras/iris/tree/master/_examples/convert-handlers).
34+
Iris has its own middleware form of `func(ctx context.Context)` but it's also compatible with all `net/http` middleware forms. See [here](https://github.com/kataras/iris/tree/master/_examples/convert-handlers).
3435

3536
Here's a small list of useful third-party handlers:
3637

middleware/i18n/i18n.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type I18n struct {
109109
locales map[string][]*ini.File
110110
}
111111

112-
// If `Config.Default` is missing and `Config.Languages` or `Config.Map` contains this key then it will set as the default locale,
112+
// If `Config.Default` is missing and `Config.Languages` or `Config.LanguagesMap` contains this key then it will set as the default locale,
113113
// no need to be exported(see `Config.Default`).
114114
const defLangCode = "en-US"
115115

0 commit comments

Comments
 (0)