pr_01m47d24b0e6n91zwymwxg0vpx/apps/web/workers/app.ts
| 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)$/; |
| 9 | const DOCS = "https://docs.g1t.sh"; |
| 10 | |
| 11 | /** Where the documentation pages that used to live under /docs are now. */ |
| 12 | const MOVED_DOCS: Record<string, string> = { |
| 13 | "/docs": "/quickstart/", |
| 14 | "/docs/concepts": "/concepts/overview/", |
| 15 | "/docs/authentication": "/guides/authentication/", |
| 16 | "/docs/git": "/guides/git/", |
| 17 | "/docs/g1t-agents": "/guides/g1t-agents/", |
| 18 | "/docs/agents": "/guides/bring-your-own-agent/", |
| 19 | "/docs/api": "/reference/api/", |
| 20 | "/docs/api/reference": "/api/reference/", |
| 21 | }; |
| 22 | |
| 23 | export default { |
| 24 | async fetch(request, env) { |
| 25 | const { pathname } = new URL(request.url); |
| 26 | // Git over HTTPS shares this hostname but belongs to the repos service. |
| 27 | if (GIT_PATH.test(pathname)) { |
| 28 | return env.REPOS.fetch(request); |
| 29 | } |
| 30 | // The documentation is its own site. |
| 31 | if (pathname === "/docs" || pathname.startsWith("/docs/")) { |
| 32 | const page = pathname.endsWith("/") ? pathname.slice(0, -1) : pathname; |
| 33 | const target = MOVED_DOCS[page] ?? "/"; |
| 34 | return Response.redirect(DOCS + target, 301); |
| 35 | } |
| 36 | return requestHandler(request); |
| 37 | }, |
| 38 | } satisfies ExportedHandler<Env>; |