mirror of
https://github.com/labstack/echo.git
synced 2025-04-25 12:24:55 +02:00
subdirectory index functionality
This commit is contained in:
parent
d04651dc2a
commit
a31fd9eb09
2
echo.go
2
echo.go
@ -338,7 +338,7 @@ func serveFile(dir, file string, c *Context) error {
|
|||||||
|
|
||||||
fi, _ := f.Stat()
|
fi, _ := f.Stat()
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
f, err = fs.Open("index.html")
|
f, err = fs.Open(file + "/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewHTTPError(http.StatusForbidden)
|
return NewHTTPError(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,14 @@ func TestEchoStatic(t *testing.T) {
|
|||||||
|
|
||||||
// Directory with index.html
|
// Directory with index.html
|
||||||
e.Static("/", "examples/website/public")
|
e.Static("/", "examples/website/public")
|
||||||
c, _ = request(GET, "/", e)
|
c, r := request(GET, "/", e)
|
||||||
assert.Equal(t, http.StatusOK, c)
|
assert.Equal(t, http.StatusOK, c)
|
||||||
|
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
|
||||||
|
|
||||||
|
// Sub-directory with index.html
|
||||||
|
c, r = request(GET, "/folder", e)
|
||||||
|
assert.Equal(t, http.StatusOK, c)
|
||||||
|
assert.Equal(t, "sub directory", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEchoMiddleware(t *testing.T) {
|
func TestEchoMiddleware(t *testing.T) {
|
||||||
|
1
examples/website/public/folder/index.html
Normal file
1
examples/website/public/folder/index.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
sub directory
|
Loading…
x
Reference in New Issue
Block a user