Skip to content

Commit

Permalink
fix: handle index.html automatically (#19)
Browse files Browse the repository at this point in the history
Resolves #17
  • Loading branch information
flakey5 committed Sep 27, 2023
1 parent cb86094 commit 3f9e22b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/handlers/helpers/directory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Env } from '../../env';
import responses from '../../responses';
import { niceBytes } from '../../util';
import { getFile } from './file';

/**
* Renders the html for a single listing entry
Expand Down Expand Up @@ -156,7 +157,15 @@ export async function listDirectory(
cursor,
});
result.delimitedPrefixes.forEach(prefix => delimitedPrefixes.add(prefix));
objects.push(...result.objects);

for (const object of result.objects) {
// Check if there's an index file and use it if there is
if (object.key.endsWith('index.html')) {
return getFile(url, request, bucketPath + 'index.html', env);
}
objects.push(object);
}

truncated = result.truncated;
cursor = result.truncated ? result.cursor : undefined;
}
Expand Down

0 comments on commit 3f9e22b

Please sign in to comment.