| 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 | |
| 11 | export type ServicePath = "git" | "packages" | null; |
| 12 | |
| 13 | export function servicePath(pathname: string): ServicePath { |
| 14 | if (REGISTRY_PATH.test(pathname)) return "packages"; |
| 15 | if (GIT_PATH.test(pathname)) return "git"; |
| 16 | return null; |
| 17 | } |