| 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 | |
| 7 | const 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`. */ |
| 9 | const REGISTRY_PATH = /^\/v2(?:\/|$)/; |
| 10 | /** The npm registry: `/-/npm/`, which `.npmrc` names for a workspace's scope. */ |
| 11 | const NPM_PATH = /^\/-\/npm(?:\/|$)/; |
| 12 | /** The Composer registries: `/-/composer/<workspace>/`, one per workspace. */ |
| 13 | const COMPOSER_PATH = /^\/-\/composer\//; |
| 14 | /** The Cargo registries: `/-/cargo/<workspace>/`, a sparse index and its web API, one per workspace. */ |
| 15 | const CARGO_PATH = /^\/-\/cargo\//; |
| 16 | /** The Maven repositories: `/-/maven/<workspace>/`, in the standard layout, one per workspace. */ |
| 17 | const MAVEN_PATH = /^\/-\/maven\//; |
| 18 | /** The NuGet feeds: `/-/nuget/<workspace>/v3/index.json` and what it names, one per workspace. */ |
| 19 | const NUGET_PATH = /^\/-\/nuget\//; |
| 20 | /** The RubyGems registries: `/-/rubygems/<workspace>/`, the compact index and `gem push`, one per workspace. */ |
| 21 | const RUBYGEMS_PATH = /^\/-\/rubygems\//; |
| 22 | |
| 23 | const REGISTRY_PATHS = [REGISTRY_PATH, NPM_PATH, COMPOSER_PATH, CARGO_PATH, MAVEN_PATH, NUGET_PATH, RUBYGEMS_PATH]; |
| 24 | |
| 25 | export type ServicePath = "git" | "packages" | null; |
| 26 | |
| 27 | export function servicePath(pathname: string): ServicePath { |
| 28 | if (REGISTRY_PATHS.some((path) => path.test(pathname))) return "packages"; |
| 29 | if (GIT_PATH.test(pathname)) return "git"; |
| 30 | return null; |
| 31 | } |