1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +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

View File

@ -338,7 +338,7 @@ func serveFile(dir, file string, c *Context) error {
fi, _ := f.Stat()
if fi.IsDir() {
f, err = fs.Open("index.html")
f, err = fs.Open(file + "/index.html")
if err != nil {
return NewHTTPError(http.StatusForbidden)
}

View File

@ -78,8 +78,14 @@ func TestEchoStatic(t *testing.T) {
// Directory with index.html
e.Static("/", "examples/website/public")
c, _ = request(GET, "/", e)
c, r := request(GET, "/", e)
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) {

View File

@ -0,0 +1 @@
sub directory