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

main
mdx 97 lines 2.44 KB
Raw
1 ---
2 title: React Router
3 description: Deploy a React Router v8 app in framework mode to Cloud Run with GCP.Website.ReactRouter.
4 sidebar:
5 order: 16
6 ---
7
8 import PackageManagers from "../../../../components/PackageManagers.astro";
9
10 export const devDeps = "@alchemy.run/frontend-frameworks";
11
12 `GCP.Website.ReactRouter` deploys a [React Router](https://reactrouter.com)
13 v8 app in framework mode to Cloud Run. Alchemy runs your own
14 `vite build` and serves the app from a Node server.
15
16 ## Install
17
18 The build integration ships separately. It only runs at deploy time,
19 so a dev dependency is enough:
20
21 <PackageManagers dev={devDeps} />
22
23 Docker has to be running when you deploy. The image is built on your
24 machine.
25
26 ## Deploy the site
27
28 ```typescript
29 // alchemy.run.ts
30 import * as Alchemy from "alchemy";
31 import * as GCP from "@alchemy.run/gcp";
32 import * as Effect from "effect/Effect";
33
34 export const Website = GCP.Website.ReactRouter("Website");
35
36 export default Alchemy.Stack(
37 "MySite",
38 { providers: GCP.providers(), state: GCP.state() },
39 Effect.gen(function* () {
40 const site = yield* Website;
41 return { url: site.url };
42 }),
43 );
44 ```
45
46 Run `alchemy deploy`. `site.url` is the Cloud Run service URL.
47
48 ## Pass environment variables
49
50 ```diff lang="typescript"
51 // alchemy.run.ts
52 -export const Website = GCP.Website.ReactRouter("Website");
53 +export const Website = GCP.Website.ReactRouter("Website", {
54 + env: {
55 + GREETING: "Hello from Cloud Run!",
56 + },
57 +});
58 ```
59
60 Loaders read it from `process.env`:
61
62 ```typescript
63 // app/routes/home.tsx
64 export function loader() {
65 return { greeting: process.env.GREETING ?? "Hello!" };
66 }
67 ```
68
69 ## Configure Vite
70
71 Your `vite.config.ts` needs no adapter. React Server Components are
72 not supported yet: the build fails with a clear error if it emits more
73 than one server entry.
74
75 ## Tune Cloud Run
76
77 ```typescript
78 export const Website = GCP.Website.ReactRouter("Website", {
79 scaling: { minInstanceCount: 1 },
80 resources: { limits: { cpu: "1", memory: "1Gi" } },
81 });
82 ```
83
84 One warm instance means no cold start for the first visitor. See
85 [Websites](/gcp/frontend/websites#tune-cloud-run) for the other
86 settings.
87
88 ## Local development
89
90 `alchemy dev` runs the framework's dev server with hot reload and
91 creates nothing in the cloud. Wrap the site in `Alchemy.remote()` to
92 deploy it for real during dev.
93
94 ## Where next
95
96 - [Websites](/gcp/frontend/websites) — the settings every site shares.
97 - [Website reference](/providers/gcp/website#reactrouter) — every prop.