Open History to see the last commit
1import * as Cloudflare from "@alchemy.run/cloudflare";
2/**
3 * The git-service example: a git host embedded in the app's own API, plus
4 * a GitHub-style web UI, on one origin.
5 *
6 * - `src/api/` — the backend, one file per piece: `auth.ts` (Better Auth
7 * and who a user is), `middleware.ts` (who may call what), `routes.ts`
8 * (the app's own routes), `api.ts` (the git routes plus ours behind the
9 * middleware), `git.ts` (the `@alchemy.run/git` block assembly), and
10 * `host.ts` (the `Cloudflare.Worker` that serves it).
11 * - `src/ui/` — the Vite SPA, a plain-fetch client of the API.
12 * - `src/worker.ts` — the website's Worker: forwards `/api/**` and the git
13 * wire paths to the GitHost over a service binding and serves the SPA for
14 * everything else, so clone URLs and the session cookie are same-host.
15 *
16 * ```sh
17 * bun run deploy
18 * ```
19 *
20 * Open the printed `webUrl`, sign up, mint an API key on the settings page,
21 * and it is the password of your git remote:
22 *
23 * ```sh
24 * git remote add origin "https://x:<key>@<host>/<you>/web.git"
25 * git push origin main
26 * ```
27 */
28import * as Alchemy from "alchemy";
29import * as Effect from "effect/Effect";
30import GitHost from "./src/api/host.ts";
31
32export default Alchemy.Stack(
33 "GitServiceExample",
34 { providers: Cloudflare.providers(), state: Alchemy.localState() },
35 Effect.gen(function* () {
36 const git = yield* GitHost;
37
38 const web = yield* Cloudflare.Website.Vite("Web", {
39 main: "src/worker.ts",
40 assets: {
41 notFoundHandling: "single-page-application",
42 runWorkerFirst: true,
43 },
44 env: {
45 GIT: GitHost,
46 },
47 });
48
49 return { url: git.url.as<string>(), webUrl: web.url };
50 }),
51);