@rsc-kit/mcp 0.41.0 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recipes.js +18 -2
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -252
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +300 -169
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +2 -2
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -542
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +270 -216
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +269 -147
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -539
- package/guides/laravel.md +0 -787
- package/guides/your-own-backend.md +0 -602
package/guides/deployment.md
DELETED
|
@@ -1,598 +0,0 @@
|
|
|
1
|
-
# Deploying
|
|
2
|
-
|
|
3
|
-
> What to ship, and the two settings that fail quietly.
|
|
4
|
-
|
|
5
|
-
`npm run build` writes one directory, and it is the deployment:
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
.output/server the server Nitro built, and the engine it calls
|
|
9
|
-
.output/public hashed assets and the pages frozen at build time
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```sh
|
|
13
|
-
npm run build
|
|
14
|
-
npm run start # node or bun .output/server/index.mjs
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
`npx vite preview` runs the same build through Vite's preview server, which is
|
|
18
|
-
what Nitro suggests at the end of a build. Both serve the real thing; `start`
|
|
19
|
-
is what a deployment runs.
|
|
20
|
-
|
|
21
|
-
## Anywhere that runs the runtime
|
|
22
|
-
|
|
23
|
-
`.output/` is self-contained. Copy it and start it — a container, a VPS, a
|
|
24
|
-
process manager, a platform that runs a Node or Bun process. There is nothing to
|
|
25
|
-
register and no platform API to satisfy, and **no `node_modules`**: the
|
|
26
|
-
dependencies are in the bundle.
|
|
27
|
-
|
|
28
|
-
```dockerfile
|
|
29
|
-
FROM oven/bun:1 AS build
|
|
30
|
-
WORKDIR /app
|
|
31
|
-
COPY package.json bun.lock ./
|
|
32
|
-
RUN bun install --frozen-lockfile
|
|
33
|
-
COPY . .
|
|
34
|
-
RUN bun run build
|
|
35
|
-
|
|
36
|
-
FROM oven/bun:1
|
|
37
|
-
WORKDIR /app
|
|
38
|
-
COPY --from=build /app/.output ./.output
|
|
39
|
-
CMD ["bun", ".output/server/index.mjs"]
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
The second stage carries `.output` and nothing else. On the docs application
|
|
43
|
-
that is 1.0 MB against 104 MB of `node_modules`.
|
|
44
|
-
|
|
45
|
-
<Aside type="tip" title="What a port measured">
|
|
46
|
-
A production app ported from Next, same pages, same backend, the Bun binary
|
|
47
|
-
image beside the Next one it replaced:
|
|
48
|
-
|
|
49
|
-
| | Next | rsc-kit |
|
|
50
|
-
| --- | --- | --- |
|
|
51
|
-
| docker image | 104.56 MiB | 50.12 MiB |
|
|
52
|
-
| docker build | 5 m 13 s | 2 m 45 s |
|
|
53
|
-
| Lighthouse | — | 99 mobile, 100 desktop |
|
|
54
|
-
|
|
55
|
-
Nothing was tuned for the numbers. The image is smaller because the bundle
|
|
56
|
-
carries no `node_modules`; the build is faster because there is one build,
|
|
57
|
-
not a build and a trace.
|
|
58
|
-
</Aside>
|
|
59
|
-
|
|
60
|
-
### A release step, and processes that are not the server
|
|
61
|
-
|
|
62
|
-
The image above starts a server because that is what the binary does with no
|
|
63
|
-
arguments. With `src/commands` it does something else with one:
|
|
64
|
-
|
|
65
|
-
```sh
|
|
66
|
-
docker run --rm myapp migrate # before the new version takes traffic
|
|
67
|
-
docker run --rm myapp work # a worker, beside the web processes
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Any platform that can run a command in the image does the same — a Kubernetes
|
|
71
|
-
Job, a release command, a process type — and nothing in the app names which.
|
|
72
|
-
See [Commands](/guides/commands/).
|
|
73
|
-
|
|
74
|
-
### Stopping gracefully
|
|
75
|
-
|
|
76
|
-
Nothing to write. A rollout sends the old process `SIGTERM` (or `SIGINT`), and
|
|
77
|
-
the built server stops the way it should:
|
|
78
|
-
|
|
79
|
-
1. It stops taking connections and gives in-flight requests
|
|
80
|
-
`SERVER_SHUTDOWN_TIMEOUT` seconds to finish (5 by default).
|
|
81
|
-
2. It calls `shutdown()` from [`instrumentation.ts`](/guides/instrumentation/)
|
|
82
|
-
if you export one, for whatever you opened: a database pool, a queue
|
|
83
|
-
client, a telemetry exporter. It gets `RSC_SHUTDOWN_TIMEOUT` seconds (10);
|
|
84
|
-
one that hangs or throws is reported and does not hold the process.
|
|
85
|
-
3. It exits with code 0.
|
|
86
|
-
|
|
87
|
-
An app with nothing open exits as soon as the drain finishes.
|
|
88
|
-
|
|
89
|
-
Two things still undo it quietly:
|
|
90
|
-
|
|
91
|
-
- **Another `SIGTERM` handler that exits.** A logger or SDK that calls
|
|
92
|
-
`process.exit()` on a signal runs first if it was imported first, and the
|
|
93
|
-
drain never starts. In-flight requests, webhooks included, are dropped on
|
|
94
|
-
every rollout, and the process exits 0, so nothing looks wrong. A logger
|
|
95
|
-
should flush on `exit`, not handle the signal.
|
|
96
|
-
- **A grace period shorter than the drain.** On Kubernetes,
|
|
97
|
-
`terminationGracePeriodSeconds` has to cover `SERVER_SHUTDOWN_TIMEOUT`, then
|
|
98
|
-
`shutdown()`, then any `preStop` sleep, or the `SIGKILL` arrives first.
|
|
99
|
-
|
|
100
|
-
## Or a platform, without a Dockerfile
|
|
101
|
-
|
|
102
|
-
Change the preset and Nitro produces what that platform expects — a Worker and
|
|
103
|
-
its `wrangler.json`, a Vercel function, a Netlify handler. See
|
|
104
|
-
[Where it runs](/hosts/where-it-runs).
|
|
105
|
-
|
|
106
|
-
### Bindings on Workers
|
|
107
|
-
|
|
108
|
-
A D1 database or an R2 bucket named in `wrangler.jsonc` is read from
|
|
109
|
-
`cloudflare:workers`, the runtime's own module — the bundle leaves it to the
|
|
110
|
-
runtime, like `bun:sqlite`. `vite dev` under Bun or Node has no such module,
|
|
111
|
-
so import it where the code runs on Workers, behind a check for the runtime:
|
|
112
|
-
|
|
113
|
-
```ts title="src/db.ts"
|
|
114
|
-
const onWorkers = typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers'
|
|
115
|
-
|
|
116
|
-
export async function db() {
|
|
117
|
-
if (onWorkers) {
|
|
118
|
-
const { env } = await import('cloudflare:workers')
|
|
119
|
-
|
|
120
|
-
return env.DB // the D1 binding, as wrangler.jsonc names it
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const { Database } = await import('bun:sqlite')
|
|
124
|
-
|
|
125
|
-
return new Database('data/local.sqlite')
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
The build renders pages through the same module, so a page that reads a
|
|
130
|
-
table with no request in it is frozen from the local database, and only the
|
|
131
|
-
pages that read the url or the request reach D1 at request time.
|
|
132
|
-
|
|
133
|
-
## Two things that fail quietly
|
|
134
|
-
|
|
135
|
-
**Do not set `NODE_ENV` when starting the server.** The build bakes its mode
|
|
136
|
-
into the bundle, so a server started with nothing set is production because it
|
|
137
|
-
was *built* that way. Setting it at start time is a second source of truth and
|
|
138
|
-
the one that can disagree — and when it disagrees the failure is silent: every
|
|
139
|
-
page renders, and none of them hydrate.
|
|
140
|
-
|
|
141
|
-
A server started with nothing set gives its own process the mode it was built
|
|
142
|
-
in, before the app loads, so `process.env.NODE_ENV` is `production` at run time
|
|
143
|
-
too. That is what a typed `env.ts` built from a spread of `process.env` reads,
|
|
144
|
-
and before 0.30.36 it read nothing and fell to its schema's
|
|
145
|
-
`.default('development')`. It also means rsc-kit's own production checks run:
|
|
146
|
-
an app that uses `refreshOn` must set `RSC_SIGNING_SECRET`, or its live pages
|
|
147
|
-
answer 500.
|
|
148
|
-
|
|
149
|
-
The check is React's debug rows in the payload:
|
|
150
|
-
|
|
151
|
-
```sh
|
|
152
|
-
curl -s https://your-app.example.com/ | grep -c ':D{'
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
`0` on a correct production build. Anything else means a development bundle
|
|
156
|
-
reached the client.
|
|
157
|
-
|
|
158
|
-
**Serve `.output/public` at the root.** Nitro does this itself, so this only
|
|
159
|
-
matters behind a CDN: point it at that directory and let the hashed filenames do
|
|
160
|
-
the caching — they are content-addressed, so they can be cached forever.
|
|
161
|
-
|
|
162
|
-
## What the document sends ahead
|
|
163
|
-
|
|
164
|
-
Every document answers with a `Link` header naming what it needs first —
|
|
165
|
-
its stylesheet, the client entry, and the fonts its layout preloads:
|
|
166
|
-
|
|
167
|
-
```
|
|
168
|
-
Link: </assets/index-D_il52MF.css>; rel=preload; as=style,
|
|
169
|
-
</assets/index-C-u4Ll0r.js>; rel=preload; as=script; crossorigin,
|
|
170
|
-
</assets/geist-latin-wght-normal-BgDaEnEv.woff2>; rel=preload; as=font; crossorigin
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Cloudflare turns that into a `103 Early Hints` sent before the origin
|
|
174
|
-
answers and cached at the edge, so those three download while the HTML is
|
|
175
|
-
still on its way; any other CDN passes it through, and a browser reads it
|
|
176
|
-
the moment the headers land, before the parser reaches the `<head>`. The
|
|
177
|
-
critical set only, never the chunks: a hint promotes what it names, and
|
|
178
|
-
naming every module demotes the document behind them. Stored documents
|
|
179
|
-
carry it too — a stored document's own head names its fonts; a rendered
|
|
180
|
-
document's head is not known until after its headers have gone, so it
|
|
181
|
-
names the stylesheet and the entry. Nothing to configure, and nothing it
|
|
182
|
-
replaces: the stylesheet still blocks paint, and inlining critical CSS
|
|
183
|
-
stacks on top of it.
|
|
184
|
-
|
|
185
|
-
The entry is a `preload` with `as=script`, not a `modulepreload`, because
|
|
186
|
-
Cloudflare builds its 103 from `preload` and `preconnect` alone and would
|
|
187
|
-
leave a `modulepreload` out. `crossorigin` gives the same fetch a module
|
|
188
|
-
script makes, so the browser uses the preloaded file and does not download
|
|
189
|
-
it twice. The document's own `<link rel="modulepreload">` is unchanged, so
|
|
190
|
-
the module is still compiled early.
|
|
191
|
-
|
|
192
|
-
## Streams and idle timeouts
|
|
193
|
-
|
|
194
|
-
An `events()` route and the [`refreshOn`](/guides/live-data)
|
|
195
|
-
stream hold a connection open and are quiet most of the time. Anything in
|
|
196
|
-
front that closes a quiet connection - the server's idle timeout, a proxy's
|
|
197
|
-
read timeout - would cut them, so each sends a keepalive line every **eight
|
|
198
|
-
seconds**: under Bun's default ten, and well under nginx's sixty and
|
|
199
|
-
Cloudflare's hundred.
|
|
200
|
-
|
|
201
|
-
If something in front closes idle connections sooner, set the keepalive
|
|
202
|
-
below it:
|
|
203
|
-
|
|
204
|
-
```sh
|
|
205
|
-
RSC_STREAM_KEEPALIVE_MS=4000 # under a 5-second idle timeout
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Too long a keepalive does not lose anything - the browser reconnects, and a
|
|
209
|
-
tab catches up on whatever moved - but every open tab is cut and reopens each
|
|
210
|
-
time the timeout passes. Both streams are sent with `Cache-Control: no-store,
|
|
211
|
-
no-transform` and are never compressed, so nothing in front buffers them.
|
|
212
|
-
|
|
213
|
-
## Secrets
|
|
214
|
-
|
|
215
|
-
rsc-kit reads up to three. Each is its own key for its own job - never reuse
|
|
216
|
-
one as another, so one leaking does not hand out the rest.
|
|
217
|
-
|
|
218
|
-
| Variable | What it protects | Who needs it | Read by |
|
|
219
|
-
| --- | --- | --- | --- |
|
|
220
|
-
| `RSC_HOST_CALL_SECRET` | calls between the renderer and a Go or Laravel backend | an app with a backend - required | the renderer **and** the backend |
|
|
221
|
-
| `RSC_SIGNING_SECRET` | the names a page hands a tab for [`refreshOn`](/guides/live-data) | an app that uses `refreshOn` - required in production | the renderer |
|
|
222
|
-
| `RSC_ACTION_ENCRYPTION_KEY` | values a server action sends through the browser, [across a deploy](#server-actions-across-a-deploy) | optional | the renderer, from the build |
|
|
223
|
-
|
|
224
|
-
`bun create rsc-kit` and `rsc-kit init` generate the first two into `.env` for
|
|
225
|
-
an app with a backend, and `php artisan rsc:install` does the same for
|
|
226
|
-
Laravel. That is development. For production, generate each once and keep it
|
|
227
|
-
where you keep secrets - your platform's environment settings, not the repo:
|
|
228
|
-
|
|
229
|
-
```sh
|
|
230
|
-
openssl rand -base64 32
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
or, without openssl:
|
|
234
|
-
|
|
235
|
-
```sh
|
|
236
|
-
node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"
|
|
237
|
-
php -r "echo base64_encode(random_bytes(32)), PHP_EOL;"
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
Three rules apply to all of them:
|
|
241
|
-
|
|
242
|
-
- **The same value on every instance.** Each is checked by a process that may
|
|
243
|
-
not be the one that issued it: a tab served by one renderer, a call landing
|
|
244
|
-
on another backend replica. A value per instance fails for some requests and
|
|
245
|
-
not others.
|
|
246
|
-
- **At runtime, from the environment.** The built server reads them when it
|
|
247
|
-
starts, so one build deploys anywhere. `RSC_ACTION_ENCRYPTION_KEY` is the
|
|
248
|
-
exception: set it at build time too.
|
|
249
|
-
- **Never in git.** The scaffold's `.gitignore` already leaves out `.env`.
|
|
250
|
-
|
|
251
|
-
**Rotating one** is a deploy, and each says so differently:
|
|
252
|
-
|
|
253
|
-
- `RSC_HOST_CALL_SECRET` - the renderer sends it and the backend checks it,
|
|
254
|
-
so the backend goes first. Give the backend the new value, with the old one
|
|
255
|
-
as `RSC_HOST_CALL_SECRET_PREVIOUS`: it answers either. Then give the
|
|
256
|
-
renderer the new value, and once every renderer has it, remove
|
|
257
|
-
`RSC_HOST_CALL_SECRET_PREVIOUS`. No call is refused along the way. The
|
|
258
|
-
renderer's own health probe takes either too. Read from `@rsc-kit/core`
|
|
259
|
-
0.30.54, `rsc-kit/go` v0.17.0 and `rsc-kit/laravel` 0.21; before those, the
|
|
260
|
-
two must change together.
|
|
261
|
-
- `RSC_SIGNING_SECRET` - pages already open hold names signed with the old
|
|
262
|
-
key. Set the old value as `RSC_SIGNING_SECRET_PREVIOUS` for the deploy that
|
|
263
|
-
rotates it: it is accepted when checking a signature and never used to make
|
|
264
|
-
one, so open tabs keep refreshing while every page rendered after the
|
|
265
|
-
rotation carries the new key. Remove it a day later. Without it, those tabs
|
|
266
|
-
stop refreshing until reloaded; nothing else breaks.
|
|
267
|
-
- `RSC_ACTION_ENCRYPTION_KEY` - an action called from a page loaded before the
|
|
268
|
-
change fails, the same window as a deploy without the key pinned.
|
|
269
|
-
|
|
270
|
-
## What the build produces
|
|
271
|
-
|
|
272
|
-
A deploy that plans before building - a binary or a folder, which script to
|
|
273
|
-
run - asks first:
|
|
274
|
-
|
|
275
|
-
```sh
|
|
276
|
-
bunx rsc-kit info --json
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
It loads the app's own Vite config the way a build does, so an `output`
|
|
280
|
-
computed in the config, or `RSC_OUTPUT=export` in the environment, resolves
|
|
281
|
-
exactly as the build will resolve it. Then every build writes the same
|
|
282
|
-
answer to `.output/rsc-kit.json` as it finishes - the confirmation, from the
|
|
283
|
-
code that decided; refuse a deploy where the two disagree:
|
|
284
|
-
|
|
285
|
-
```json
|
|
286
|
-
{ "version": "0.30.33", "output": "server", "compile": "compile:binary", "binary": "dist/app" }
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
```json
|
|
290
|
-
{ "version": "0.29.6", "output": "export", "dir": "dist" }
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
- **`output: "server"`** - run the server. `compile` and `binary` are there
|
|
294
|
-
when the app's `package.json` has a compile step: run the script `compile`
|
|
295
|
-
names after the build, and the file its `--outfile` names is the single
|
|
296
|
-
binary to ship. It is `compile:binary` when the app has one, which compiles
|
|
297
|
-
the output the build just wrote. Otherwise it is `compile`, which usually
|
|
298
|
-
runs `vite build` again first; the build says so, and a scaffolded app has
|
|
299
|
-
both.
|
|
300
|
-
- **`output: "export"`** - `dir` is the static site; serve it as files.
|
|
301
|
-
|
|
302
|
-
Two fields are only in the build's file, because only the build knows them:
|
|
303
|
-
`commands`, the app's [commands](/guides/commands), and `backendPaths`. Compare
|
|
304
|
-
the rest with `info`.
|
|
305
|
-
|
|
306
|
-
### Sending the backend's urls past the renderer
|
|
307
|
-
|
|
308
|
-
`backendPaths` is the app's
|
|
309
|
-
[`rscKit({ backendPaths })`](/hosts/backend-answered-pages/), normalised, and
|
|
310
|
-
`[]` when it names none, so a proxy can tell "none" from a build too old to say
|
|
311
|
-
(before 0.30.53). The renderer forwards those urls to the backend anyway, but
|
|
312
|
-
every request it forwards costs its CPU and memory and is cut off by its
|
|
313
|
-
timeouts. A proxy in front can send them straight to the backend. The list is
|
|
314
|
-
the plain prefixes only, so "equal to one or under it" stays the whole rule: an
|
|
315
|
-
entry with a dynamic segment (`'/login/[provider]'`) is left out, and reaches
|
|
316
|
-
the backend through the renderer.
|
|
317
|
-
|
|
318
|
-
```json
|
|
319
|
-
{ "version": "0.30.53", "output": "server", "backendPaths": ["/auth", "/github"] }
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
- A path equal to a prefix, or under it (`/auth`, `/auth/callback`, but not
|
|
323
|
-
`/authors`), goes to the backend, for every method.
|
|
324
|
-
- Everything else goes to the renderer.
|
|
325
|
-
- The host-call endpoint (`/__rsc/host-call`, or `RSC_HOST_CALL_PATH`) is
|
|
326
|
-
refused from outside. Only the renderer calls it, straight to the backend.
|
|
327
|
-
The build refuses a `backendPaths` entry that would cover it, and the
|
|
328
|
-
renderer answers a browser's request for it with its not-found page instead
|
|
329
|
-
of forwarding it.
|
|
330
|
-
|
|
331
|
-
The same list is `build.backendPaths` in the `routes.json` beside the entries,
|
|
332
|
-
for a host that reads the route table.
|
|
333
|
-
|
|
334
|
-
### A header on every request to the backend
|
|
335
|
-
|
|
336
|
-
When something in front of the backend admits the renderer only with a header
|
|
337
|
-
of its own, such as a private preview's access token, set
|
|
338
|
-
`RSC_BACKEND_HEADERS` on the renderer to a JSON object:
|
|
339
|
-
|
|
340
|
-
```ini
|
|
341
|
-
RSC_BACKEND_HEADERS={"X-Preview-Token":"..."}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
- They go on every request the renderer makes to `RSC_BACKEND`: host calls,
|
|
345
|
-
and the urls it forwards. They go to no other origin.
|
|
346
|
-
- The renderer reads them once, when it starts, so a new value needs a
|
|
347
|
-
restart.
|
|
348
|
-
- A visitor's header with the same name is replaced, never passed through.
|
|
349
|
-
- Malformed JSON stops the server at startup, with an error that names the
|
|
350
|
-
variable but never its value.
|
|
351
|
-
- Names rsc-kit sets itself (`X-RSC-*`, `Cookie`, `Authorization`, `Host`,
|
|
352
|
-
`Content-Type`, the forwarding headers) are refused.
|
|
353
|
-
- `httpHostCalls({ headers })` takes the same, for a host that embeds the
|
|
354
|
-
engine itself.
|
|
355
|
-
|
|
356
|
-
Read from `@rsc-kit/core` 0.30.54. Production and a backend on loopback rarely
|
|
357
|
-
need it.
|
|
358
|
-
|
|
359
|
-
### Pages an edge may serve from its cache
|
|
360
|
-
|
|
361
|
-
rsc-kit implements the [edge contract](/reference/edge-contract): one marker
|
|
362
|
-
and two endpoints that an edge uses the same way for every framework that
|
|
363
|
-
implements it. next-bun-compile implements it too. The edge serves a static
|
|
364
|
-
page whole and a PPR page's shell straight from its cache, and has the origin
|
|
365
|
-
render only a shell's holes, onto the same response. [Edge
|
|
366
|
-
caching](/guides/edge-caching) covers what that buys. What rsc-kit puts in it:
|
|
367
|
-
|
|
368
|
-
- **`.output/edge.json`** is written by every server build, with empty lists
|
|
369
|
-
when there is nothing to list. An export writes none.
|
|
370
|
-
- **`shells`** are the pages the build report marks `◐`, as patterns. **`static`**
|
|
371
|
-
are the pages it marks `○`, each at the path it was rendered at. Both leave
|
|
372
|
-
out every page with middleware above it (a `middleware.ts`, or the host's
|
|
373
|
-
`export const middleware`), since middleware decides per request who may see
|
|
374
|
-
the page, and every page bound from the request's host (`app/[domain]/`),
|
|
375
|
-
since a path cannot say which host it is. `static` also leaves out a frozen
|
|
376
|
-
redirect and a page a listed shell pattern matches.
|
|
377
|
-
- **A root `middleware.ts` empties both lists**, since it is above every page,
|
|
378
|
-
and the build names the middleware that kept each page out. Headers that are
|
|
379
|
-
the same on every page belong in `rscKit({ headers })` instead (see
|
|
380
|
-
[security headers](/guides/response-headers#security-headers)): they keep the
|
|
381
|
-
page listed, and `/_edge/page` hands them to the edge as the page's
|
|
382
|
-
`headers`.
|
|
383
|
-
- **Past 200**, `shells` drops the deepest and `static` keeps the shallowest,
|
|
384
|
-
and the build says which. A page left out is served by the origin, which
|
|
385
|
-
answers it correctly.
|
|
386
|
-
- **`build`** covers the client bundle and the bytes of every stored page, shell
|
|
387
|
-
and postponed state, so a release that changes only what the server rendered
|
|
388
|
-
is a new build, and an edge drops what it cached before it. It is not the
|
|
389
|
-
version a browser tab sees: a server-only change does not make open tabs
|
|
390
|
-
reload.
|
|
391
|
-
- **A static page's payload** is copied to `/assets/_rsc/<hash>.rsc`, served
|
|
392
|
-
`immutable` like the rest of `/assets/`, and named in the document, so the
|
|
393
|
-
page hydrates without asking the origin for anything.
|
|
394
|
-
- **`EDGE_TOKEN`** switches both endpoints on. The platform sets it; without
|
|
395
|
-
it, everything under `/_edge/` is a 404.
|
|
396
|
-
- **The resume's body is ignored.** rsc-kit hands out `"state": ""` and reads
|
|
397
|
-
the postponed state from its own build, so it never parses what a caller
|
|
398
|
-
wrote.
|
|
399
|
-
|
|
400
|
-
### The files: `.output/files.json`
|
|
401
|
-
|
|
402
|
-
A server in front of the app — nginx, a CDN, a PHP front controller — can
|
|
403
|
-
answer the app's files from disk without asking it. Everything in the public
|
|
404
|
-
directory is served before the renderer is reached, so nothing of the app runs
|
|
405
|
-
for a file: no `middleware.ts`, no `route.ts`, and `rscKit({ headers })` is a
|
|
406
|
-
page's, not a file's. Every server build says what that takes:
|
|
407
|
-
|
|
408
|
-
```json
|
|
409
|
-
{
|
|
410
|
-
"v": 1,
|
|
411
|
-
"root": "public",
|
|
412
|
-
"files": ["/assets/app-1a2b3c4d.js", "/favicon.ico", "/sw.js"],
|
|
413
|
-
"precompressed": ["br", "gzip", "zstd"],
|
|
414
|
-
"headers": [
|
|
415
|
-
{ "match": "/_app/**", "headers": { "cache-control": "public, max-age=0, must-revalidate" } },
|
|
416
|
-
{ "match": "/assets/**", "headers": { "cache-control": "public, max-age=31536000, immutable" } },
|
|
417
|
-
{ "match": "/sw.js", "headers": { "cache-control": "public, max-age=0, must-revalidate" } },
|
|
418
|
-
{ "match": "/sw-app.js", "headers": { "cache-control": "public, max-age=0, must-revalidate" } },
|
|
419
|
-
{ "match": "/manifest.webmanifest", "headers": { "cache-control": "public, max-age=0, must-revalidate" } }
|
|
420
|
-
],
|
|
421
|
-
"middleware": false
|
|
422
|
-
}
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
It is written to the build's output directory, beside `rsc-kit.json` and
|
|
426
|
-
`edge.json`: `.output/` for the `bun`, `node` and Cloudflare Workers presets,
|
|
427
|
-
`.vercel/output/` on Vercel - wherever Nitro's `output.dir` is.
|
|
428
|
-
|
|
429
|
-
- **`files`** is every file a request may be answered with, by url path,
|
|
430
|
-
relative to `root` (which is relative to `files.json`). A path is the file's
|
|
431
|
-
name as it is on disk, not percent-encoded: decode the request's path before
|
|
432
|
-
looking it up, as the app does. Under a `baseURL` the paths carry it. Nothing
|
|
433
|
-
else under `root` is public: the stored pages a Workers build copies there,
|
|
434
|
-
a platform's `_headers` and `_redirects`, and a server bundle built inside
|
|
435
|
-
the public directory are not in it.
|
|
436
|
-
- **`precompressed`** names the encodings a file may also exist in, as a
|
|
437
|
-
sibling with the suffix (`/sw.js.br`, `.gz`, `.zst`). Send it with
|
|
438
|
-
`Content-Encoding` and `Vary: Accept-Encoding` when the request accepts it.
|
|
439
|
-
- **`headers`** are what a file goes out with beyond its `Content-Type`: each
|
|
440
|
-
applies to an exact path, or, ending in `/**`, to every path under it.
|
|
441
|
-
Apply every entry that matches, in order; a later one replaces an earlier
|
|
442
|
-
one's header of the same name. They are the route rules the build's own
|
|
443
|
-
server uses, including any the app sets on `/**`, so a front that sends them
|
|
444
|
-
answers exactly as the app would. The files rsc-kit writes under a fixed
|
|
445
|
-
name - `/sw.js`, `/sw-app.js` (your `src/app/sw.js`), `/manifest.webmanifest`
|
|
446
|
-
and everything under `/_app/` - are `public, max-age=0, must-revalidate`, and
|
|
447
|
-
their ETag makes each check a 304: a service worker kept by a heuristic cache
|
|
448
|
-
installs the previous deploy's file list against the new server. A file no
|
|
449
|
-
entry matches, such as your own `public/favicon.ico`, gets no
|
|
450
|
-
`Cache-Control`; add a route rule if you want one.
|
|
451
|
-
- **`middleware`** is always `false`, and says so rather than leave a front
|
|
452
|
-
to wonder whether a guard is skipped.
|
|
453
|
-
|
|
454
|
-
The list fails closed. A route rule the manifest cannot state - a pattern
|
|
455
|
-
like `/:name.js`, a `redirect`, `cors` or `proxy` rule, a `headers: false`
|
|
456
|
-
reset - would make a front's answer differ from the app's with nobody seeing
|
|
457
|
-
it, so a file under one is left out of `files` and its request goes to the
|
|
458
|
-
app. The build checks each file against Nitro's own matcher, and says which
|
|
459
|
-
it left out and why.
|
|
460
|
-
|
|
461
|
-
A file from a previous deploy is not in the list and need not be kept: an
|
|
462
|
-
open tab that asks for a chunk the new server no longer has reloads the
|
|
463
|
-
document, and a page request from the old build is answered 409 and reloads
|
|
464
|
-
once.
|
|
465
|
-
|
|
466
|
-
Do not work the list out from the files in `.output/server/rsc-static/`. A
|
|
467
|
-
guarded page has a shell on disk too, `_team_` cannot say whether it was a
|
|
468
|
-
parameter or a folder of that name, and the folder's layout is not a contract.
|
|
469
|
-
|
|
470
|
-
A build carries no backend address and no secret. `RSC_BACKEND`,
|
|
471
|
-
`RSC_HOST_CALL_SECRET` and `RSC_SIGNING_SECRET` are read when the server
|
|
472
|
-
runs, so one build runs against whichever backend its deployment names, and
|
|
473
|
-
rotating a secret is a restart, not a rebuild.
|
|
474
|
-
|
|
475
|
-
## Is it ready
|
|
476
|
-
|
|
477
|
-
`GET /_rsc/health` says whether this renderer can serve, for a platform
|
|
478
|
-
deciding when to route to it - which an open port alone does not say:
|
|
479
|
-
|
|
480
|
-
```json
|
|
481
|
-
{ "ok": true, "version": "08f805d3", "backend": "ok" }
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
- **200** - up. `backend` is `"ok"` when the backend answered, `"none"` for
|
|
485
|
-
an app without one.
|
|
486
|
-
- **503** - the backend did not answer within 2 seconds: unreachable, or
|
|
487
|
-
refusing the secret.
|
|
488
|
-
|
|
489
|
-
Why it is not ready names the app's insides, so the reason and `backend` go
|
|
490
|
-
only to a probe that sends the host-call secret, as `x-rsc-host-secret`.
|
|
491
|
-
Anyone else gets `{ "ok": true }` or `{ "ok": false }` and the status - which
|
|
492
|
-
is all a router needs. Not keyed on localhost: behind a reverse proxy on the
|
|
493
|
-
same machine, every visitor is localhost.
|
|
494
|
-
|
|
495
|
-
The backend check asks the route guards with none to run - every adapter
|
|
496
|
-
passes an empty list - so it runs no app code and reads no data, yet it
|
|
497
|
-
proves the address, the network, the shared secret and the adapter. Never
|
|
498
|
-
cached; `HEAD` answers with the status alone.
|
|
499
|
-
|
|
500
|
-
## Pages across a deploy
|
|
501
|
-
|
|
502
|
-
A page from the previous build asks for a payload from the new one, whose
|
|
503
|
-
client components its own manifest cannot load. Every document carries
|
|
504
|
-
which build it is (`<meta name="rsc-kit:build">`, an id derived from the
|
|
505
|
-
client entry), the client sends it as `X-RSC-Version` on every payload
|
|
506
|
-
request, and a server on another build answers `409` with where to go;
|
|
507
|
-
the client loads the document from the current build, once. A payload that
|
|
508
|
-
still names a client reference the page lacks — a CDN answering from cache,
|
|
509
|
-
say — reloads the document the same way a missing chunk does. Nothing to
|
|
510
|
-
configure, and nothing to set: the id is the client's, so a deploy that
|
|
511
|
-
changed only the server leaves every open page alone. There is no
|
|
512
|
-
override — a version set anywhere else would disagree with what the
|
|
513
|
-
document says, and a client's honest claim would be refused on every
|
|
514
|
-
navigation.
|
|
515
|
-
|
|
516
|
-
## Server actions across a deploy
|
|
517
|
-
|
|
518
|
-
A server action can close over server-side values, and React encrypts those
|
|
519
|
-
before sending them to the browser so the page cannot read them. The process
|
|
520
|
-
that decrypts them on the way back has to hold the same key.
|
|
521
|
-
|
|
522
|
-
By default that key is generated at build time and baked in. Every instance
|
|
523
|
-
running the same build agrees, so the only exposure is the deploy itself: a
|
|
524
|
-
browser sitting on a page from the old build calls an action on the new one,
|
|
525
|
-
and the key has changed underneath it. The call fails.
|
|
526
|
-
|
|
527
|
-
For most apps that window is seconds and nobody notices. If yours is long
|
|
528
|
-
enough to care about — a slow rollout, long-lived pages, an app people leave
|
|
529
|
-
open — pin the key:
|
|
530
|
-
|
|
531
|
-
```sh
|
|
532
|
-
# once, kept wherever you keep secrets
|
|
533
|
-
openssl rand -base64 32
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
```sh
|
|
537
|
-
RSC_ACTION_ENCRYPTION_KEY=<that value>
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
Set it at **build time** and the build stops baking its own; the value is read
|
|
541
|
-
from the environment when the server runs, so the same artifact deploys
|
|
542
|
-
anywhere.
|
|
543
|
-
|
|
544
|
-
:::danger[Set it everywhere or nowhere]
|
|
545
|
-
Half-configured is worse than unconfigured. If one instance reads the variable
|
|
546
|
-
and another falls back to a baked key, they disagree, and the symptom is an
|
|
547
|
-
action that fails for some visitors and not others with nothing in the logs
|
|
548
|
-
pointing at a key.
|
|
549
|
-
|
|
550
|
-
Unset, everything works — the build-time key is used, which is the default
|
|
551
|
-
precisely because it cannot be got half right.
|
|
552
|
-
:::
|
|
553
|
-
|
|
554
|
-
## Frozen pages and the routes that own them
|
|
555
|
-
|
|
556
|
-
`.output/public` holds whole frozen pages and PPR shells alongside the assets.
|
|
557
|
-
They are read through the `prerendered` reader, which is a function rather than a
|
|
558
|
-
directory precisely so a runtime with no filesystem — a Worker — can supply them
|
|
559
|
-
from a binding instead.
|
|
560
|
-
|
|
561
|
-
A route that declares middleware is never cached publicly: it is sent as
|
|
562
|
-
`private, no-store`, because middleware runs per visitor. If something in front
|
|
563
|
-
of your app also owns the response — an auth proxy re-issuing a session on
|
|
564
|
-
pass-through — give the paths it covers a `middleware.ts` so this host knows
|
|
565
|
-
they are covered. See [edge caching](/guides/edge-caching).
|
|
566
|
-
|
|
567
|
-
## Rebuild on deploy
|
|
568
|
-
|
|
569
|
-
Cached responses carry a build version, so a deploy invalidates them.
|
|
570
|
-
|
|
571
|
-
**Build, then start — never build under a running server.** The server loads
|
|
572
|
-
its rsc and ssr services lazily, on the first request that needs each, and
|
|
573
|
-
a `vite build` that is rewriting `.output/` at that moment hands it a file
|
|
574
|
-
that is half-written or briefly missing. The runtime caches that failed
|
|
575
|
-
import — Bun does, and so does Node's ESM loader — so the route answers 500
|
|
576
|
-
with an `ENOENT` for a file that now exists, and keeps doing so until the
|
|
577
|
-
process restarts. In development use `vite` (the dev server), which owns its
|
|
578
|
-
own rebuilds; in production build into a fresh directory or stop the server
|
|
579
|
-
first, and start it against a finished `.output/`.
|
|
580
|
-
|
|
581
|
-
Ship `.output/` from the same commit as the code that serves it. A server
|
|
582
|
-
running one build against another's frozen pages is the one combination nothing
|
|
583
|
-
checks for you.
|
|
584
|
-
|
|
585
|
-
## HTTP/2 in front
|
|
586
|
-
|
|
587
|
-
Every client component is its own chunk, so a page loads only the code it
|
|
588
|
-
renders — and a page with many of them makes several small requests. Over
|
|
589
|
-
HTTP/2 or HTTP/3 those share one connection and cost nothing extra; over
|
|
590
|
-
HTTP/1.1 a browser opens at most six connections per origin and the rest
|
|
591
|
-
queue.
|
|
592
|
-
|
|
593
|
-
Behind Cloudflare there is nothing to do: HTTP/2 and HTTP/3 are on by default,
|
|
594
|
-
for proxied sites and Workers alike. The case to check is a Bun or Node server
|
|
595
|
-
exposed to the internet directly, which speaks HTTP/1.1 — put anything that
|
|
596
|
-
speaks HTTP/2 in front of it (a CDN, an ingress controller, Caddy, nginx), which
|
|
597
|
-
is how almost every deployment runs anyway. `curl -sI --http2 https://your.site`
|
|
598
|
-
answers `HTTP/2` when it is right.
|