1
0
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:
Chase Hutchins 2015-06-19 17:39:05 -07:00
parent d04651dc2a
commit a31fd9eb09
3 changed files with 9 additions and 2 deletions
echo.goecho_test.go
examples/website/public/folder

@ -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) {

@ -0,0 +1 @@
sub directory