diff --git a/.gitignore b/.gitignore index e71f2af..cf4177c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules/ .wrangler/ dist/ -.dev.vars \ No newline at end of file +.dev.vars diff --git a/src/constants/limits.ts b/src/constants/limits.ts new file mode 100644 index 0000000..e1c0219 --- /dev/null +++ b/src/constants/limits.ts @@ -0,0 +1,4 @@ +/** + * Max amount of retries for S3 requests + */ +export const S3_RETRY_LIMIT = 3; diff --git a/src/handlers/strategies/directoryListing.ts b/src/handlers/strategies/directoryListing.ts index 8cfec11..a02bb3e 100644 --- a/src/handlers/strategies/directoryListing.ts +++ b/src/handlers/strategies/directoryListing.ts @@ -12,6 +12,7 @@ import { getFile } from './serveFile'; // Imports the Precompiled Handlebars Template import htmlTemplate from '../../templates/directoryListing.out.js'; +import { S3_RETRY_LIMIT } from '../../constants/limits'; // Applies the Template into a Handlebars Template Function const handleBarsTemplate = Handlebars.template(htmlTemplate); @@ -120,7 +121,7 @@ async function fetchR2Result( ): Promise { let result: ListObjectsV2CommandOutput | undefined = undefined; - let retriesRemaining = 3; + let retriesRemaining = S3_RETRY_LIMIT; while (retriesRemaining > 0) { try { // Send request to R2 diff --git a/tests/e2e/directory.test.ts b/tests/e2e/directory.test.ts index cc64212..62eae59 100644 --- a/tests/e2e/directory.test.ts +++ b/tests/e2e/directory.test.ts @@ -10,6 +10,11 @@ async function startS3Mock(): Promise { const url = new URL(req.url!, `http://${req.headers.host}`); let xmlFilePath = './tests/e2e/test-data/expected-s3/'; + + // Check if it's a path that's supposed to exist in + // later tests. If so, return a S3 response indicating that + // the path exists. Otherwise return a S3 response indicating + // that the path doesn't exist if ( ['nodejs/release/', 'nodejs/', 'metrics/'].includes( url.searchParams.get('prefix')!