flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/workers/app.ts

38 lines1,354 bytesCodeBlame
1import { createRequestHandler } from "react-router";
2
3const requestHandler = createRequestHandler(
4 () => import("virtual:react-router/server-build"),
5 import.meta.env.MODE,
6);
7
8const GIT_PATH = /\/(info\/refs|git-upload-pack|git-receive-pack)$/;
9const DOCS = "https://docs.g1t.sh";
10
11/** Where the documentation pages that used to live under /docs are now. */
12const 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
23export 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>;