Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use itty-router for routing requests #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/update-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: npm install

- name: Update Redirect Links
run: node scripts/update-redirect-links.js && npm run format
run: node scripts/update-latest-versions.js && npm run format
env:
CF_ACCESS_KEY_ID: ${{ secrets.CF_ACCESS_KEY_ID }}
CF_SECRET_ACCESS_KEY: ${{ secrets.CF_SECRET_ACCESS_KEY }}
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"glob": "^10.3.10",
"nodejs-latest-linker": "^1.7.0",
"prettier": "^3.0.3",
"terser": "^5.20.0",
"tsx": "^4.7.2",
"typescript": "^5.2.2",
"wrangler": "^3.22.1",
"nodejs-latest-linker": "^1.7.0"
"wrangler": "^3.22.1"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.423.0",
"handlebars": "^4.7.8",
"itty-router": "^5.0.17",
"toucan-js": "^3.3.1",
"zod": "^3.22.3"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ const client = new S3Client({
(async function main() {
const allDirs = await listDirectory(RELEASE_DIR);
const linker = new Linker({ baseDir: RELEASE_DIR, docsDir: DOCS_DIR });
const links = await linker.getLinks(allDirs, dir => listDirectory(`${dir}/`));
const allLinks = await linker.getLinks(allDirs, dir =>
listDirectory(`${dir}/`)
);

const latestLinks = Array.from(allLinks).filter(link =>
link[0].startsWith('nodejs/release')
);
latestLinks.forEach(link => {
link[0] = link[0].substring('nodejs/release/'.length);
link[1] = link[1].substring('nodejs/release/'.length);
});

await writeFile(
'./src/constants/redirectLinks.json',
JSON.stringify(Array.from(links), null, 2) + '\n'
'./src/constants/latestVersions.json',
JSON.stringify(Object.fromEntries(latestLinks), null, 2) + '\n'
);
})();

Expand Down
2 changes: 0 additions & 2 deletions src/constants/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const CACHE = caches.default;

export const CACHE_HEADERS = {
success: 'public, max-age=3600, s-maxage=14400',
failure: 'private, no-cache, no-store, max-age=0, must-revalidate',
Expand Down
33 changes: 33 additions & 0 deletions src/constants/latestVersions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"latest-v0.10.x": "v0.10.48",
"latest-v0.12.x": "v0.12.18",
"latest-v4.x": "v4.9.1",
"latest-argon": "v4.9.1",
"latest-v5.x": "v5.12.0",
"latest-v6.x": "v6.17.1",
"latest-boron": "v6.17.1",
"latest-v7.x": "v7.10.1",
"latest-v8.x": "v8.17.0",
"latest-carbon": "v8.17.0",
"latest-v9.x": "v9.11.2",
"latest-v10.x": "v10.24.1",
"latest-dubnium": "v10.24.1",
"latest-v11.x": "v11.15.0",
"latest-v12.x": "v12.22.12",
"latest-erbium": "v12.22.12",
"latest-v13.x": "v13.14.0",
"latest-v14.x": "v14.21.3",
"latest-fermium": "v14.21.3",
"latest-v15.x": "v15.14.0",
"latest-v16.x": "v16.20.2",
"latest-gallium": "v16.20.2",
"latest-v17.x": "v17.9.1",
"latest-v18.x": "v18.19.0",
"latest-hydrogen": "v18.19.0",
"latest-v19.x": "v19.9.0",
"latest-v20.x": "v20.10.0",
"latest-iron": "v20.10.0",
"latest-v21.x": "v21.2.0",
"latest": "v21.2.0",
"node-latest.tar.gz": "v21.2.0/node-v21.2.0.tar.gz"
}
34 changes: 2 additions & 32 deletions src/constants/r2Prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@
// later on.
// (e.g. url path `/dist` points to R2 path `nodejs/release`)
// See https://raw.githubusercontent.com/nodejs/build/main/ansible/www-standalone/resources/config/nodejs.org
import map from './redirectLinks.json' assert { type: 'json' };
import latestVersions from './latestVersions.json' assert { type: 'json' };

export const REDIRECT_MAP = new Map(map as [string, string][]);

export const DIST_PATH_PREFIX = 'nodejs/release';

export const DOWNLOAD_PATH_PREFIX = 'nodejs';

export const DOCS_PATH_PREFIX = 'nodejs/docs';

export const API_PATH_PREFIX = `${REDIRECT_MAP.get('nodejs/docs/latest')}/api`;

export const VIRTUAL_DIRS: Record<string, Set<string>> = {
'docs/': new Set(
[...REDIRECT_MAP]
.filter(([key]) => key.startsWith('nodejs/docs/'))
.reverse()
.map(([key]) => key.substring('nodejs/docs/'.length) + '/')
),
};

export const URL_TO_BUCKET_PATH_MAP: Record<string, (path: string) => string> =
{
dist: (path): string =>
DIST_PATH_PREFIX + (path.substring('/dist'.length) || '/'),
download: (path): string =>
DOWNLOAD_PATH_PREFIX + (path.substring('/download'.length) || '/'),
docs: (path): 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 /
};
export const LATEST_RELEASES: Record<string, string> = latestVersions;
Loading
Loading