Skip to content

Commit

Permalink
src: use itty-router for routing requests
Browse files Browse the repository at this point in the history
Closes #122

Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Jun 30, 2024
1 parent 73f151c commit 6073527
Show file tree
Hide file tree
Showing 42 changed files with 716 additions and 1,435 deletions.
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
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
21 changes: 0 additions & 21 deletions src/constants/r2Prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import map from './redirectLinks.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]
Expand All @@ -23,16 +15,3 @@ export const VIRTUAL_DIRS: Record<string, Set<string>> = {
.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 /
};
22 changes: 0 additions & 22 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,10 @@ export interface Env {
* Bucket name
*/
BUCKET_NAME: string;
/**
* Directory listing toggle
* on - Enabled for all paths
* restricted - Directory listing enabled only for paths we want to be listed
* off - No directory
* In prod, this should *always* be restricted
*/
DIRECTORY_LISTING: 'on' | 'restricted' | 'off';
/**
* Api key for /_cf/cache-purge. If undefined, the endpoint is disabled.
*/
CACHE_PURGE_API_KEY?: string;
/**
* Sentry DSN, used for error monitoring
* If missing, Sentry isn't used
*/
SENTRY_DSN?: string;
/**
* If true and all retries to R2 fail, we will rewrite the request to
* https://direct.nodejs.org
*/
USE_FALLBACK_WHEN_R2_FAILS: boolean;
/**
* Host for the www/Digital Ocean/origin server
*/
FALLBACK_HOST: string;

ORIGIN_HOST: string;
}
109 changes: 0 additions & 109 deletions src/handlers/get.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/handlers/handler.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/handlers/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/handlers/options.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/handlers/post.ts

This file was deleted.

92 changes: 0 additions & 92 deletions src/handlers/strategies/cachePurge.ts

This file was deleted.

Loading

0 comments on commit 6073527

Please sign in to comment.