Skip to content

Commit c3bb29c

Browse files
index.html now gets resolved for any subfolder too (+tests)
1 parent 314f3d9 commit c3bb29c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

application/lambda/lambda.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ func (local *localLambda) writeStaticFile(path string, out io.Writer) error {
194194
if err != nil {
195195
return err
196196
}
197+
dir, err := f.Readdir(1)
198+
if len(dir) > 0 {
199+
f.Close()
200+
return local.writeStaticFile( path + "/index.html", out )
201+
}
197202
defer f.Close()
198203
_, err = io.Copy(out, f)
199204
return err

application/lambda/lambda_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func TestStaticFile(t *testing.T) {
152152
require.NoError(t, os.WriteFile(filepath.Join(d, "static", "foo", "foo"), []byte("foo page"), 0755))
153153
require.NoError(t, os.Mkdir(filepath.Join(d, "static", "foo", "bar"), 0755))
154154
require.NoError(t, os.WriteFile(filepath.Join(d, "static", "foo", "bar", "bar"), []byte("bar page"), 0755))
155+
require.NoError(t, os.WriteFile(filepath.Join(d, "static", "foo","index.html"), []byte("sub index page"), 0755))
155156

156157
fn, err := DummyPublic(d, "cat", "-")
157158
require.NoError(t, err)
@@ -189,6 +190,21 @@ func TestStaticFile(t *testing.T) {
189190
require.NoError(t, err)
190191
assert.Equal(t, "bar page", string(content))
191192
})
193+
t.Run("sub path with index.html served (no trailing slash)", func(t *testing.T) {
194+
content, err := testRequest(fn, http.MethodGet, "/f/foo", nil)
195+
require.NoError(t, err)
196+
assert.Equal(t, "sub index page", string(content))
197+
})
198+
t.Run("sub path with index.html served (with trailing slash)", func(t *testing.T) {
199+
content, err := testRequest(fn, http.MethodGet, "/f/foo/", nil)
200+
require.NoError(t, err)
201+
assert.Equal(t, "sub index page", string(content))
202+
})
203+
t.Run("sub path with index.html served (with trailing slash + index.html)", func(t *testing.T) {
204+
content, err := testRequest(fn, http.MethodGet, "/f/foo/index.html", nil)
205+
require.NoError(t, err)
206+
assert.Equal(t, "sub index page", string(content))
207+
})
192208
}
193209

194210
func testRequest(fn application.Invokable, method string, path string, payload []byte) ([]byte, error) {

0 commit comments

Comments
 (0)