g1t/apps/web/app/lib/registry-paths.ts

21 lines961 bytesCodeBlame
1/**
2 * Which requests to g1t.sh belong to a service other than the site: git
3 * over HTTPS (the repos service) and the package registries (the packages
4 * service). `workers/app.ts` hands each to its binding as it is.
5 */
6
7const GIT_PATH = /\/(info\/refs|git-upload-pack|git-receive-pack)$/;
8/** The container registry: OCI Distribution's `/v2/`, and its token endpoint at `/v2/token`. */
9const REGISTRY_PATH = /^\/v2(?:\/|$)/;
10/** The npm registry: `/-/npm/`, which `.npmrc` names for a workspace's scope. */
11const NPM_PATH = /^\/-\/npm(?:\/|$)/;
12/** The Composer registries: `/-/composer/<workspace>/`, one per workspace. */
13const COMPOSER_PATH = /^\/-\/composer\//;
14
15export type ServicePath = "git" | "packages" | null;
16
17export function servicePath(pathname: string): ServicePath {
18 if (REGISTRY_PATH.test(pathname) || NPM_PATH.test(pathname) || COMPOSER_PATH.test(pathname)) return "packages";
19 if (GIT_PATH.test(pathname)) return "git";
20 return null;
21}