Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Initial g1t: services, event bus, intents and attempts | 1 | import { createRequestHandler } from "react-router"; |
| 2 | ||
| 3 | const requestHandler = createRequestHandler( | |
| 4 | () => import("virtual:react-router/server-build"), | |
| 5 | import.meta.env.MODE, | |
| 6 | ); | |
| 7 | ||
| 8 | const GIT_PATH = /\/(info\/refs|git-upload-pack|git-receive-pack)$/; | |
| docs.g1t.sh, generated OpenAPI with an interactive reference, full footer | 9 | const DOCS_HOST = "docs.g1t.sh"; |
| 10 | const SITE = "https://g1t.sh"; | |
| 11 | ||
| 12 | /** | |
| 13 | * docs.g1t.sh serves the site's /docs pages from its root: /concepts there | |
| 14 | * is /docs/concepts here. Anything on that hostname that is not | |
| 15 | * documentation belongs to the main site. | |
| 16 | */ | |
| 17 | function docsRequest(request: Request, url: URL): Request | Response { | |
| 18 | const { pathname } = url; | |
| 19 | if (pathname === "/docs" || pathname.startsWith("/docs/")) return request; | |
| 20 | // React Router's data requests for in-site navigation. | |
| 21 | if (pathname.startsWith("/__manifest") || pathname.endsWith(".data")) return request; | |
| 22 | const first = pathname.split("/")[1]; | |
| 23 | if (DOCS_PAGES.has(first)) { | |
| 24 | url.pathname = "/docs" + (pathname === "/" ? "" : pathname); | |
| 25 | return new Request(url, request); | |
| 26 | } | |
| 27 | return Response.redirect(SITE + pathname + url.search, 302); | |
| 28 | } | |
| Initial g1t: services, event bus, intents and attempts | 29 | |
| docs.g1t.sh, generated OpenAPI with an interactive reference, full footer | 30 | /** First path segments that are documentation; "" is the docs home page. */ |
| 31 | const DOCS_PAGES = new Set([ | |
| 32 | "", | |
| 33 | "concepts", | |
| 34 | "authentication", | |
| 35 | "git", | |
| 36 | "g1t-agents", | |
| 37 | "agents", | |
| 38 | "api", | |
| 39 | ]); | |
| 40 | ||
| Initial g1t: services, event bus, intents and attempts | 41 | export default { |
| 42 | async fetch(request, env) { | |
| docs.g1t.sh, generated OpenAPI with an interactive reference, full footer | 43 | const url = new URL(request.url); |
| Initial g1t: services, event bus, intents and attempts | 44 | // Git over HTTPS shares this hostname but belongs to the repos service. |
| docs.g1t.sh, generated OpenAPI with an interactive reference, full footer | 45 | if (GIT_PATH.test(url.pathname)) { |
| Initial g1t: services, event bus, intents and attempts | 46 | return env.REPOS.fetch(request); |
| 47 | } | |
| docs.g1t.sh, generated OpenAPI with an interactive reference, full footer | 48 | if (url.hostname === DOCS_HOST) { |
| 49 | const rewritten = docsRequest(request, url); | |
| 50 | if (rewritten instanceof Response) return rewritten; | |
| 51 | return requestHandler(rewritten); | |
| 52 | } | |
| Initial g1t: services, event bus, intents and attempts | 53 | return requestHandler(request); |
| 54 | }, | |
| 55 | } satisfies ExportedHandler<Env>; |