Skip to content
Merged
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
58 changes: 58 additions & 0 deletions e2e-tests/directory.kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,61 @@ test('GET `/dist` redirects to `/dist/`', async () => {
expect(res.status).toBe(301);
expect(res.headers.get('location')).toStrictEqual('https://localhost/dist/');
});

for (const prefix of ['/dist', '/download/release']) {
test(`GET \`${prefix}/docs/\` returns 200`, async () => {
const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v0.0.1/`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.mutable
);
});

// Dir that actually exists in `nodejs/docs/`
test(`GET \`${prefix}/docs/v0.0.1/\` returns 200`, async () => {
const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v0.0.1/`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.mutable
);
});

// Dir that's just a symlink `nodejs/docs/` -> `nodejs/release/v20.0.0/docs/`
test(`GET \`${prefix}/docs/v20.0.0/\` returns 200`, async () => {
const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v20.0.0/`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.mutable
);
});
}
64 changes: 64 additions & 0 deletions e2e-tests/directory.s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,67 @@ test('GET `/dist` redirects to `/dist/`', async () => {
expect(res.status).toBe(301);
expect(res.headers.get('location')).toStrictEqual('https://localhost/dist/');
});

for (const prefix of ['/dist', '/download/release']) {
test(`GET \`${prefix}/docs/\` returns 200`, async () => {
mockS3Response(S3_DIRECTORY_RESULT);

const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v0.0.1/`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.mutable
);
});

// Dir that actually exists in `nodejs/docs/`
test(`GET \`${prefix}/docs/v0.0.1/\` returns 200`, async () => {
mockS3Response(S3_DIRECTORY_RESULT);

const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v0.0.1/`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.mutable
);
});

// Dir that's just a symlink `nodejs/docs/` -> `nodejs/release/v20.0.0/docs/`
test(`GET \`${prefix}/docs/v20.0.0/\` returns 200`, async () => {
mockS3Response(S3_DIRECTORY_RESULT);

const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v20.0.0/`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.mutable
);
});
}
58 changes: 58 additions & 0 deletions e2e-tests/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,64 @@ test('GET `/dist/asd123.json` returns 404', async () => {
expect(await res.text()).toStrictEqual('File not found');
});

for (const prefix of ['/dist', '/download/release']) {
test(`GET \`${prefix}/docs/index.html\` returns 200`, async () => {
const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v0.0.1/index.html`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.immutable
);
});

// Dir that actually exists in `nodejs/docs/`
test(`GET \`${prefix}/docs/v0.0.1/index.html\` returns 200`, async () => {
const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v0.0.1/index.html`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.immutable
);
});

// Dir that's just a symlink `nodejs/docs/` -> `nodejs/release/v20.0.0/docs/`
test(`GET \`${prefix}/docs/v20.0.0/api/index.html\` returns 200`, async () => {
const ctx = createExecutionContext();

const res = await worker.fetch(
new Request(`https://localhost${prefix}/docs/v20.0.0/api/index.html`),
mockedEnv,
ctx
);

// Consume the body promise
await res.text();

expect(res.status).toBe(200);
expect(res.headers.get('cache-control')).toStrictEqual(
CACHE_HEADERS.immutable
);
});
}

test('`if-modified-since` header', async () => {
const ctx = createExecutionContext();

Expand Down
21 changes: 21 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ export function registerRoutes(router: Router): void {
router.head('/llms.txt', r2Middleware);
router.get('/llms.txt', r2Middleware);

// `/dist/docs/...` is a symlink to `nodejs/docs/`
const distDocsDirToDocsDirRewrite = new SubtitutionMiddleware(
router,
'/dist/docs',
'/docs'
);
router.head('/dist/docs*', distDocsDirToDocsDirRewrite);
router.get('/dist/docs*', distDocsDirToDocsDirRewrite);

// `/download/release/docs/...` is a symlink to `nodejs/docs/`
const mainlineReleaseDocsDirToDocsDirRewrite = new SubtitutionMiddleware(
router,
'/download/release/docs',
'/docs'
);
router.head(
'/download/release/docs*',
mainlineReleaseDocsDirToDocsDirRewrite
);
router.get('/download/release/docs*', mainlineReleaseDocsDirToDocsDirRewrite);

router.head('/dist/:filePath+?', r2Middleware);
router.get('/dist/:filePath+?', r2Middleware);

Expand Down
6 changes: 6 additions & 0 deletions src/utils/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ describe('isImmutablePath', () => {
'/dist/v20.0.0/node-v20.0.0-linux-x64.tar.gz',
'/download/release/v20.0.0/node-v20.0.0.pkg',
'/docs/v18.0.0/api/fs.html',
'/dist/docs/v20.0.0/api/index.html',
'/download/release/v20.0.0/api/index.html',
])('returns true for immutable asset `%s`', path => {
expect(isImmutablePath(path)).toEqual(true);
});
Expand All @@ -31,6 +33,10 @@ describe('isImmutablePath', () => {
// `latest` aliases point at moving content
'/dist/latest/node-v20.0.0-linux-x64.tar.gz',
'/docs/latest/api/fs.html',
'/dist/docs/latest/api/index.html',
'/download/release/latest/api/index.html',
'/dist/docs/',
'/download/docs/',
'/download/release/latest/win-x64/node_pdb.7z',
'/dist/latest-v20.x/node-v20.0.0.tar.gz',
// Legacy `latest-v0.X.x` aliases
Expand Down
Loading