Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/middleware/r2Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ function getR2Path({
if (pathname.startsWith('/dist')) {
return `nodejs/release/${filePath}`;
} else if (pathname.startsWith('/download')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO none of this (line 152-180) belongs here, this should be part of our custom mapings (ie a Map() or something that contains rewrites/mappings) instead of hardcoded if/else statements. These become larger and larger and harder to maintain, and in general if-statements shouldn't be this deep or convoluted 😅

return `nodejs/${filePath}`;
if (pathname.startsWith('/download/docs/')) {
if (params.version !== undefined && !docsDirectory.includes(params.version)) {
return `nodejs/release/${params.version}/docs/${filePath}`;
} else {
return `nodejs/docs/${filePath}`;
}
} else {
return `nodejs/${filePath}`;
}
} else if (pathname.startsWith('/api')) {
return `nodejs/release/${latestVersions['latest']}/docs/api/${filePath}`;
} else if (pathname.startsWith('/docs')) {
Expand Down
6 changes: 6 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export function registerRoutes(router: Router): void {

router.head(`/docs/${branch}*`, subtitutionMiddleware);
router.get(`/docs/${branch}*`, subtitutionMiddleware);

router.head(`/download/docs/${branch}*`, subtitutionMiddleware);
router.get(`/download/docs/${branch}*`, subtitutionMiddleware);
}

router.head('/node-config-schema.json', r2Middleware);
Expand All @@ -53,6 +56,9 @@ export function registerRoutes(router: Router): void {
router.head('/dist/?:filePath+', r2Middleware, originMiddleware);
router.get('/dist/?:filePath+', r2Middleware, originMiddleware);

router.head('/download/docs/?:version?/:filePath+?', r2Middleware, originMiddleware);
router.get('/download/docs/?:version?/:filePath+?', r2Middleware, originMiddleware);

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

Expand Down