Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions middleware/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ func (config StaticConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
if !isIgnorableOpenFileError(err) {
return err
}

if config.HTML5 {
html5File, html5Err := currentFS.Open(filePath + ".html")
if html5Err == nil {
defer html5File.Close()

html5Info, err := html5File.Stat()
if err != nil {
return err
}

return serveFile(c, html5File, html5Info)
}
}
// file with that path did not exist, so we continue down in middleware/handler chain, hoping that we end up in
// handler that is meant to handle this request
err = next(c)
Expand Down Expand Up @@ -270,6 +284,20 @@ func (config StaticConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
if info.IsDir() {
index, err := currentFS.Open(path.Join(filePath, config.Index))
if err != nil {
if config.HTML5 && !config.Browse {
html5File, html5Err := currentFS.Open(filePath + ".html")
if html5Err == nil {
defer html5File.Close()

info, err = html5File.Stat()
if err != nil {
return err
}

return serveFile(c, html5File, info)
}
}

if config.Browse {
return listDir(dirListTemplate, filePath, currentFS, c.Response())
}
Expand Down
10 changes: 10 additions & 0 deletions middleware/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func TestStatic(t *testing.T) {
expectCode: http.StatusOK,
expectContains: "<h1>Hello from index</h1>",
},
{
name: "ok, when html5 mode serve route html next to a directory",
givenConfig: &StaticConfig{
Root: "testdata/dist/public",
HTML5: true,
},
whenURL: "/camera",
expectCode: http.StatusOK,
expectContains: "<h1>Camera page</h1>",
},
{
name: "ok, serve index as directory index listing files directory",
givenConfig: &StaticConfig{
Expand Down
1 change: 1 addition & 0 deletions middleware/testdata/dist/public/camera.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Camera page</h1>
1 change: 1 addition & 0 deletions middleware/testdata/dist/public/camera/route.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
camera route directory