From ad812220643557bad7163c102a9a761478edcc45 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Wed, 29 May 2024 11:48:53 -0400 Subject: [PATCH 1/2] Remove /metrics redirects --- src/constants/r2Prefixes.ts | 1 - src/utils/path.ts | 3 --- tests/e2e/directory.test.ts | 16 +--------------- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/constants/r2Prefixes.ts b/src/constants/r2Prefixes.ts index 4d4fd4d..f429f10 100644 --- a/src/constants/r2Prefixes.ts +++ b/src/constants/r2Prefixes.ts @@ -34,5 +34,4 @@ export const URL_TO_BUCKET_PATH_MAP: Record string> = DOCS_PATH_PREFIX + (path.substring('/docs'.length) || '/'), api: (path): string => API_PATH_PREFIX + (path.substring('/api'.length) || '/'), - metrics: (path): string => path.substring(1), // substring to cut off the / }; diff --git a/src/utils/path.ts b/src/utils/path.ts index 6c9e348..69f453c 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -147,9 +147,6 @@ export function mapBucketPathToUrlPath( } else if (bucketPath.startsWith(DOWNLOAD_PATH_PREFIX)) { // Rest of the `/download/...` paths (e.g. `/download/nightly/`) return [`/download${bucketPath.substring(DOWNLOAD_PATH_PREFIX.length)}`]; - } else if (bucketPath.startsWith('metrics')) { - // Metrics doesn't need any redirects - return ['/' + bucketPath]; } return env.DIRECTORY_LISTING === 'restricted' diff --git a/tests/e2e/directory.test.ts b/tests/e2e/directory.test.ts index 6d07794..1d956e8 100644 --- a/tests/e2e/directory.test.ts +++ b/tests/e2e/directory.test.ts @@ -24,7 +24,7 @@ async function startS3Mock(): Promise { const r2Prefix = url.searchParams.get('prefix')!; let doesFolderExist = - ['nodejs/release/', 'nodejs/', 'nodejs/docs/', 'metrics/'].includes( + ['nodejs/release/', 'nodejs/', 'nodejs/docs/'].includes( r2Prefix ) || r2Prefix.endsWith('/docs/api/'); @@ -143,20 +143,6 @@ describe('Directory Tests (Restricted Directory Listing)', () => { assert.strictEqual(res.status, 200); }); - it('redirects `/metrics` to `/metrics/`', async () => { - const originalRes = await mf.dispatchFetch(`${url}metrics`, { - redirect: 'manual', - }); - assert.strictEqual(originalRes.status, 301); - const res = await mf.dispatchFetch(originalRes.headers.get('location')!); - assert.strictEqual(res.status, 200); - }); - - it('allows `/metrics/`', async () => { - const res = await mf.dispatchFetch(`${url}metrics/`); - assert.strictEqual(res.status, 200); - }); - it('returns 401 for unrecognized base paths', async () => { let res = await mf.dispatchFetch(url); assert.strictEqual(res.status, 401); From 339fa59825d4dadeb66bd1f72bdf94aec6f1e198 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Wed, 29 May 2024 11:54:07 -0400 Subject: [PATCH 2/2] fixup! prettier --- tests/e2e/directory.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/directory.test.ts b/tests/e2e/directory.test.ts index 1d956e8..51b051c 100644 --- a/tests/e2e/directory.test.ts +++ b/tests/e2e/directory.test.ts @@ -24,9 +24,8 @@ async function startS3Mock(): Promise { const r2Prefix = url.searchParams.get('prefix')!; let doesFolderExist = - ['nodejs/release/', 'nodejs/', 'nodejs/docs/'].includes( - r2Prefix - ) || r2Prefix.endsWith('/docs/api/'); + ['nodejs/release/', 'nodejs/', 'nodejs/docs/'].includes(r2Prefix) || + r2Prefix.endsWith('/docs/api/'); if (doesFolderExist) { xmlFilePath += 'ListObjectsV2-exists.xml';