mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
Merge branch 'master' into v12
Former-commit-id: 50fae564bda3607f4f4208fdcb72f835c1751a1e
This commit is contained in:
commit
6d60a65339
|
@ -15,7 +15,8 @@ func newApp() *iris.Application {
|
||||||
// app.HandleDir("/css", "./assets/css")
|
// app.HandleDir("/css", "./assets/css")
|
||||||
// app.HandleDir("/js", "./assets/js")
|
// app.HandleDir("/js", "./assets/js")
|
||||||
|
|
||||||
app.HandleDir("/static", "./assets", iris.DirOptions{
|
v1 := app.Party("/v1")
|
||||||
|
v1.HandleDir("/static", "./assets", iris.DirOptions{
|
||||||
// Defaults to "/index.html", if request path is ending with **/*/$IndexName
|
// Defaults to "/index.html", if request path is ending with **/*/$IndexName
|
||||||
// then it redirects to **/*(/) which another handler is handling it,
|
// then it redirects to **/*(/) which another handler is handling it,
|
||||||
// that another handler, called index handler, is auto-registered by the framework
|
// that another handler, called index handler, is auto-registered by the framework
|
||||||
|
@ -33,15 +34,15 @@ func newApp() *iris.Application {
|
||||||
})
|
})
|
||||||
|
|
||||||
// You can also register any index handler manually, order of registration does not matter:
|
// You can also register any index handler manually, order of registration does not matter:
|
||||||
// app.Get("/static", [...custom middleware...], func(ctx iris.Context) {
|
// v1.Get("/static", [...custom middleware...], func(ctx iris.Context) {
|
||||||
// [...custom code...]
|
// [...custom code...]
|
||||||
// ctx.ServeFile("./assets/index.html", false)
|
// ctx.ServeFile("./assets/index.html", false)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// http://localhost:8080/static
|
// http://localhost:8080/v1/static
|
||||||
// http://localhost:8080/static/css/main.css
|
// http://localhost:8080/v1/static/css/main.css
|
||||||
// http://localhost:8080/static/js/jquery-2.1.1.js
|
// http://localhost:8080/v1/static/js/jquery-2.1.1.js
|
||||||
// http://localhost:8080/static/favicon.ico
|
// http://localhost:8080/v1/static/favicon.ico
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"github.com/kataras/iris/v12/httptest"
|
"github.com/kataras/iris/v12/httptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const prefixURL = "/v1"
|
||||||
|
|
||||||
type resource string
|
type resource string
|
||||||
|
|
||||||
func (r resource) contentType() string {
|
func (r resource) contentType() string {
|
||||||
|
@ -85,7 +87,7 @@ func TestFileServerBasic(t *testing.T) {
|
||||||
url := u.String()
|
url := u.String()
|
||||||
contents := u.loadFromBase("./assets")
|
contents := u.loadFromBase("./assets")
|
||||||
|
|
||||||
e.GET(url).Expect().
|
e.GET(prefixURL+url).Expect().
|
||||||
Status(httptest.StatusOK).
|
Status(httptest.StatusOK).
|
||||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||||
Body().Equal(contents)
|
Body().Equal(contents)
|
||||||
|
|
|
@ -485,7 +485,8 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
routes = append(routes, api.createRoutes([]string{http.MethodGet}, s.RequestPath, h)...)
|
requestPath := s.RequestPath[strings.Index(s.RequestPath, api.relativePath)+len(api.relativePath):]
|
||||||
|
routes = append(routes, api.createRoutes([]string{http.MethodGet}, requestPath, h)...)
|
||||||
getRoute.StaticSites = append(getRoute.StaticSites, s)
|
getRoute.StaticSites = append(getRoute.StaticSites, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user