@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 106 lines 3.72 KB
Raw
1 import type { InputProps } from "alchemy/Input";
2 import * as Namespace from "alchemy/Namespace";
3 import { makeFrameworkSite, type FrameworkSiteProps } from "./FrameworkSite.ts";
4
5 /** The framework-integration package that drives the React Router build. */
6 export const REACT_ROUTER_FRAMEWORK_SPECIFIER = "@alchemy.run/frontend-frameworks/react-router";
7
8 /** The AWS Lambda deploy target for the React Router build. */
9 export const REACT_ROUTER_AWS_TARGET_SPECIFIER =
10 "@alchemy.run/frontend-frameworks/react-router/aws";
11
12 /** The Node deploy target for the Lambda Web Function server (the default). */
13 export const REACT_ROUTER_WEB_TARGET_SPECIFIER =
14 "@alchemy.run/frontend-frameworks/react-router/node";
15
16 export type ReactRouterProps = FrameworkSiteProps;
17
18 /**
19 * Deploy a [React Router](https://reactrouter.com) v7 app (framework mode)
20 * to AWS: the SSR server on a Lambda Web Function, client assets in S3, and
21 * a CloudFront distribution whose edge router serves uploaded files from S3
22 * and forwards everything else to the server.
23 *
24 * The server runs on a Lambda Web Function: the framework's Node server
25 * (built with the `@alchemy.run/frontend-frameworks/react-router/node` deploy
26 * target) serves many requests per environment and streams responses. Set
27 * `server: "function"` to use a Lambda Function behind a streaming Function
28 * URL instead, built with the `/aws` target below, for Regions without Web
29 * Functions.
30 *
31 * The build runs through
32 * `@alchemy.run/frontend-frameworks/react-router` with the
33 * `@alchemy.run/frontend-frameworks/react-router/aws` deploy target — both
34 * must be installed in your project, alongside `@react-router/dev`,
35 * `react-router`, and `vite`.
36 *
37 * Your `vite.config.ts` needs no adapter wiring. React Router's server
38 * build is a `ServerBuild` manifest rather than a request handler, so the
39 * integration makes the server pass's build input a module that wraps the
40 * manifest with `createRequestHandler`, forces the SSR bundle to be
41 * self-contained, and packages the resulting fetch handler as a streaming
42 * Lambda handler.
43 *
44 * React Server Components (React Router's `unstable` RSC plugin) and
45 * multi-environment builds are not supported yet — the build fails with an
46 * actionable error when more than one server entry is emitted.
47 *
48 * ### Creating React Router Sites
49 * **Example:** Basic React Router App
50 * ```typescript
51 * const site = yield* AWS.Website.ReactRouter("Web", {
52 * rootDir: "./app",
53 * });
54 * ```
55 *
56 * **Example:** Custom Domain
57 * ```typescript
58 * const site = yield* AWS.Website.ReactRouter("Web", {
59 * rootDir: "./app",
60 * domain: {
61 * name: "app.example.com",
62 * hostedZoneId: zone.hostedZoneId,
63 * },
64 * });
65 * ```
66 *
67 * ### Server Configuration
68 * **Example:** Tune The Server Function
69 * ```typescript
70 * const site = yield* AWS.Website.ReactRouter("Web", {
71 * rootDir: "./app",
72 * memorySize: 2048,
73 * env: {
74 * API_BASE: api.url,
75 * },
76 * });
77 * ```
78 *
79 * **Example:** Read An Environment Variable From A Loader
80 * ```typescript
81 * // app/routes/home.tsx
82 * export function loader() {
83 * return { apiBase: process.env.API_BASE ?? "unset" };
84 * }
85 * ```
86 *
87 * ### Shared Router
88 * **Example:** Serve Through An Existing Router
89 * ```typescript
90 * const router = yield* AWS.Website.Router("FrontDoor", {});
91 *
92 * const site = yield* AWS.Website.ReactRouter("Web", {
93 * rootDir: "./app",
94 * domain: { router },
95 * });
96 * ```
97 *
98 * @resource
99 */
100 export const ReactRouter = (id: string, props: InputProps<ReactRouterProps, "server"> = {}) =>
101 makeFrameworkSite(id, props, {
102 name: "ReactRouter",
103 framework: REACT_ROUTER_FRAMEWORK_SPECIFIER,
104 target: REACT_ROUTER_AWS_TARGET_SPECIFIER,
105 webTarget: REACT_ROUTER_WEB_TARGET_SPECIFIER,
106 }).pipe(Namespace.push(id));