@rshono/core 1.0.0-rc.0 → 1.0.0-rc.10
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/README.md +202 -159
- package/dist/builder/page-files.d.ts.map +1 -1
- package/dist/builder/page-files.js +7 -3
- package/dist/builder/page-files.js.map +1 -1
- package/dist/builder/public-env.d.ts +6 -0
- package/dist/builder/public-env.d.ts.map +1 -1
- package/dist/builder/public-env.js +6 -0
- package/dist/builder/public-env.js.map +1 -1
- package/dist/builder/rspack-config.d.ts +3 -3
- package/dist/builder/rspack-config.d.ts.map +1 -1
- package/dist/builder/rspack-config.js +62 -16
- package/dist/builder/rspack-config.js.map +1 -1
- package/dist/cli/build.d.ts +2 -2
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/dev.d.ts +2 -2
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dev.js +63 -35
- package/dist/cli/dev.js.map +1 -1
- package/dist/cli/index.js +10 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/config.d.ts +58 -70
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -1
- package/dist/config.js.map +1 -1
- package/dist/deploy/cloudflare/build.js +1 -1
- package/dist/deploy/cloudflare/build.js.map +1 -1
- package/dist/deploy/cloudflare/runtime.d.ts.map +1 -1
- package/dist/deploy/cloudflare/runtime.js +7 -37
- package/dist/deploy/cloudflare/runtime.js.map +1 -1
- package/dist/deploy/contract.d.ts +22 -16
- package/dist/deploy/contract.d.ts.map +1 -1
- package/dist/deploy/contract.js.map +1 -1
- package/dist/deploy/filesystem.d.ts +1 -1
- package/dist/deploy/filesystem.d.ts.map +1 -1
- package/dist/deploy/filesystem.js +7 -10
- package/dist/deploy/filesystem.js.map +1 -1
- package/dist/deploy/node/runtime.d.ts +4 -0
- package/dist/deploy/node/runtime.d.ts.map +1 -1
- package/dist/deploy/node/runtime.js +24 -3
- package/dist/deploy/node/runtime.js.map +1 -1
- package/dist/deploy/presets.d.ts +3 -3
- package/dist/deploy/presets.d.ts.map +1 -1
- package/dist/deploy/presets.js +13 -30
- package/dist/deploy/presets.js.map +1 -1
- package/dist/deploy/vercel/runtime.d.ts.map +1 -1
- package/dist/deploy/vercel/runtime.js +0 -3
- package/dist/deploy/vercel/runtime.js.map +1 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts +85 -48
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +4 -6
- package/dist/router.js.map +1 -1
- package/dist/runtime/boundaries.d.ts +39 -25
- package/dist/runtime/boundaries.d.ts.map +1 -1
- package/dist/runtime/boundaries.js +22 -17
- package/dist/runtime/boundaries.js.map +1 -1
- package/dist/runtime/client.d.ts +9 -8
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +9 -8
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/context.d.ts +216 -70
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +299 -93
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/control.d.ts.map +1 -1
- package/dist/runtime/control.js +7 -0
- package/dist/runtime/control.js.map +1 -1
- package/dist/runtime/dev-protocol.d.ts.map +1 -1
- package/dist/runtime/dev-protocol.js.map +1 -1
- package/dist/runtime/entry.client.d.ts +4 -0
- package/dist/runtime/entry.client.d.ts.map +1 -1
- package/dist/runtime/entry.client.js +190 -154
- package/dist/runtime/entry.client.js.map +1 -1
- package/dist/runtime/entry.rsc.d.ts.map +1 -1
- package/dist/runtime/entry.rsc.js +145 -159
- package/dist/runtime/entry.rsc.js.map +1 -1
- package/dist/runtime/entry.ssr.d.ts +9 -1
- package/dist/runtime/entry.ssr.d.ts.map +1 -1
- package/dist/runtime/entry.ssr.js +36 -18
- package/dist/runtime/entry.ssr.js.map +1 -1
- package/dist/runtime/flight-inject.d.ts +31 -0
- package/dist/runtime/flight-inject.d.ts.map +1 -0
- package/dist/runtime/flight-inject.js +221 -0
- package/dist/runtime/flight-inject.js.map +1 -0
- package/dist/runtime/navigation.d.ts +20 -38
- package/dist/runtime/navigation.d.ts.map +1 -1
- package/dist/runtime/navigation.js +10 -53
- package/dist/runtime/navigation.js.map +1 -1
- package/dist/runtime/request.d.ts +6 -0
- package/dist/runtime/request.d.ts.map +1 -1
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/request.js.map +1 -1
- package/dist/runtime/server.d.ts +7 -12
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/runtime/server.js +15 -12
- package/dist/runtime/server.js.map +1 -1
- package/dist/server/headers.d.ts +9 -9
- package/dist/server/headers.js +9 -9
- package/dist/server/headers.js.map +1 -1
- package/dist/server/load-config.d.ts +2 -2
- package/dist/server/load-config.d.ts.map +1 -1
- package/dist/server/load-config.js +22 -11
- package/dist/server/load-config.js.map +1 -1
- package/dist/server/prerendered.d.ts +43 -15
- package/dist/server/prerendered.d.ts.map +1 -1
- package/dist/server/prerendered.js +47 -0
- package/dist/server/prerendered.js.map +1 -1
- package/dist/server/server-config.d.ts +13 -39
- package/dist/server/server-config.d.ts.map +1 -1
- package/dist/server/server-config.js +5 -74
- package/dist/server/server-config.js.map +1 -1
- package/dist/server/ssg.d.ts +2 -2
- package/dist/server/ssg.d.ts.map +1 -1
- package/dist/server/ssg.js +21 -34
- package/dist/server/ssg.js.map +1 -1
- package/package.json +13 -16
- package/dist/deploy/bun/runtime.d.ts +0 -11
- package/dist/deploy/bun/runtime.d.ts.map +0 -1
- package/dist/deploy/bun/runtime.js +0 -22
- package/dist/deploy/bun/runtime.js.map +0 -1
- package/dist/deploy/deno/runtime.d.ts +0 -11
- package/dist/deploy/deno/runtime.d.ts.map +0 -1
- package/dist/deploy/deno/runtime.js +0 -16
- package/dist/deploy/deno/runtime.js.map +0 -1
- package/dist/deploy/listen.d.ts +0 -20
- package/dist/deploy/listen.d.ts.map +0 -1
- package/dist/deploy/listen.js +0 -24
- package/dist/deploy/listen.js.map +0 -1
- package/dist/deploy/netlify/build.d.ts +0 -8
- package/dist/deploy/netlify/build.d.ts.map +0 -1
- package/dist/deploy/netlify/build.js +0 -52
- package/dist/deploy/netlify/build.js.map +0 -1
- package/dist/deploy/netlify/runtime.d.ts +0 -13
- package/dist/deploy/netlify/runtime.d.ts.map +0 -1
- package/dist/deploy/netlify/runtime.js +0 -24
- package/dist/deploy/netlify/runtime.js.map +0 -1
- package/dist/server/compress.d.ts +0 -15
- package/dist/server/compress.d.ts.map +0 -1
- package/dist/server/compress.js +0 -76
- package/dist/server/compress.js.map +0 -1
package/dist/runtime/server.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@rshono/core/server` — the request-scoped surface, for use inside server components
|
|
3
|
-
* and `'use server'` action modules:
|
|
4
|
-
* params, env and middleware variables, the
|
|
5
|
-
* control-flow helpers, and
|
|
6
|
-
* framework catches.
|
|
3
|
+
* and `'use server'` action modules: `getRequestContext()` for the URL, cookies,
|
|
4
|
+
* params, env and middleware variables, the `redirect()` and `notFound()`
|
|
5
|
+
* control-flow helpers, and `onServerError()` for reporting the errors the
|
|
6
|
+
* framework catches. Plus `publicUrl(c)`, for middleware in `src/server.ts`, which
|
|
7
|
+
* is handed Hono's `c` rather than a request context.
|
|
7
8
|
*
|
|
8
9
|
* Server-only. Importing this from a `'use client'` module is a mistake — those
|
|
9
10
|
* run in the browser (and are SSR'd without a bound context). Read what you need
|
|
10
11
|
* on the server and pass it down as props, or use `useNavigation()` from
|
|
11
12
|
* `@rshono/core/client` for URL data.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
* implemented: that module also exports the plumbing the framework's own entry
|
|
15
|
-
* points need (`runWithContext`, `readParams`, `publicUrl`, `reportServerError`),
|
|
16
|
-
* and pointing the `./server` subpath straight at it published every one of them —
|
|
17
|
-
* `@internal` in the docs, but present in a consumer's autocomplete and pinned by
|
|
18
|
-
* semver all the same. They stay reachable by relative import, which is the only
|
|
19
|
-
* way the framework itself ever reaches them.
|
|
14
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreserver | Docs — `@rshono/core/server`}
|
|
20
15
|
*
|
|
21
16
|
* @packageDocumentation
|
|
22
17
|
*/
|
|
23
|
-
|
|
18
|
+
// A barrel rather than pointing the `./server` subpath straight at `./context.js`, where all of this
|
|
19
|
+
// is implemented: that module also exports the framework's own plumbing (`runWithContext`,
|
|
20
|
+
// `readParams`, `reportServerError`), and exposing it would put every one of those in a consumer's
|
|
21
|
+
// autocomplete and under semver. They stay reachable by relative import.
|
|
22
|
+
export { getRequestContext, notFound, onServerError,
|
|
23
|
+
// For middleware, which is handed Hono's `c` and so has no request context to read a URL from.
|
|
24
|
+
// Hono's own middleware all resolve the origin from `c.req.url`, which is the internal address
|
|
25
|
+
// behind a proxy — this is what `trustProxy` means to them.
|
|
26
|
+
publicUrl, redirect, } from './context.js';
|
|
24
27
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,qGAAqG;AACrG,2FAA2F;AAC3F,mGAAmG;AACnG,yEAAyE;AACzE,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,aAAa;AACb,+FAA+F;AAC/F,+FAA+F;AAC/F,4DAA4D;AAC5D,SAAS,EACT,QAAQ,GAST,MAAM,cAAc,CAAC","sourcesContent":["/**\n * `@rshono/core/server` — the request-scoped surface, for use inside server components\n * and `'use server'` action modules: `getRequestContext()` for the URL, cookies,\n * params, env and middleware variables, the `redirect()` and `notFound()`\n * control-flow helpers, and `onServerError()` for reporting the errors the\n * framework catches. Plus `publicUrl(c)`, for middleware in `src/server.ts`, which\n * is handed Hono's `c` rather than a request context.\n *\n * Server-only. Importing this from a `'use client'` module is a mistake — those\n * run in the browser (and are SSR'd without a bound context). Read what you need\n * on the server and pass it down as props, or use `useNavigation()` from\n * `@rshono/core/client` for URL data.\n *\n * @see {@link https://www.rshono.com/docs/api#rshonocoreserver | Docs — `@rshono/core/server`}\n *\n * @packageDocumentation\n */\n\n// A barrel rather than pointing the `./server` subpath straight at `./context.js`, where all of this\n// is implemented: that module also exports the framework's own plumbing (`runWithContext`,\n// `readParams`, `reportServerError`), and exposing it would put every one of those in a consumer's\n// autocomplete and under semver. They stay reachable by relative import.\nexport {\n getRequestContext,\n notFound,\n onServerError,\n // For middleware, which is handed Hono's `c` and so has no request context to read a URL from.\n // Hono's own middleware all resolve the origin from `c.req.url`, which is the internal address\n // behind a proxy — this is what `trustProxy` means to them.\n publicUrl,\n redirect,\n type EnvVars,\n type RedirectStatus,\n // A type, not a value: `RequestContext` is handed to you by `getRequestContext()` or the `ctx` page\n // prop — one instance per request — and is never constructed by application code.\n type RequestContext,\n type ServerErrorContext,\n type ServerErrorHandler,\n type ServerErrorSource,\n} from './context.js';\n"]}
|
package/dist/server/headers.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Small header utilities shared by the response-header defaults
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Small header utilities shared by the response-header defaults and the prerendered-page cache. Kept
|
|
3
|
+
* apart from both because getting `Vary` and `ETag` comparison subtly wrong is exactly the kind of
|
|
4
|
+
* thing that only shows up behind a CDN.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Adds `value` to the `Vary` header without discarding what is already there.
|
|
8
8
|
*
|
|
9
|
-
* `Vary` is a list, and
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* `Vary` is a list, and the framework's own entry (`Accept` — an HTML document or a flight payload from
|
|
10
|
+
* one URL) is not necessarily the only one: a route, a middleware or a proxy may have added its own.
|
|
11
|
+
* A plain `set` would drop the others, and a cache would then serve one variant in place of another.
|
|
12
|
+
* `*` is left alone: it already means "never reuse this".
|
|
13
13
|
*/
|
|
14
14
|
export declare function appendVary(headers: Headers, value: string): void;
|
|
15
15
|
/**
|
|
@@ -17,8 +17,8 @@ export declare function appendVary(headers: Headers, value: string): void;
|
|
|
17
17
|
* exact body and should be answered with a 304.
|
|
18
18
|
*
|
|
19
19
|
* The header carries a *list*, and each entry may be weak (`W/"…"`). The weak prefix is ignored on
|
|
20
|
-
* both sides
|
|
21
|
-
*
|
|
20
|
+
* both sides: a proxy or CDN that gzips on the way out changes the bytes without changing the
|
|
21
|
+
* representation, and is entitled to weaken the validator when it does.
|
|
22
22
|
*/
|
|
23
23
|
export declare function etagMatches(ifNoneMatch: string | undefined, etag: string): boolean;
|
|
24
24
|
//# sourceMappingURL=headers.d.ts.map
|
package/dist/server/headers.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Small header utilities shared by the response-header defaults
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Small header utilities shared by the response-header defaults and the prerendered-page cache. Kept
|
|
3
|
+
* apart from both because getting `Vary` and `ETag` comparison subtly wrong is exactly the kind of
|
|
4
|
+
* thing that only shows up behind a CDN.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Adds `value` to the `Vary` header without discarding what is already there.
|
|
8
8
|
*
|
|
9
|
-
* `Vary` is a list, and
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* `Vary` is a list, and the framework's own entry (`Accept` — an HTML document or a flight payload from
|
|
10
|
+
* one URL) is not necessarily the only one: a route, a middleware or a proxy may have added its own.
|
|
11
|
+
* A plain `set` would drop the others, and a cache would then serve one variant in place of another.
|
|
12
|
+
* `*` is left alone: it already means "never reuse this".
|
|
13
13
|
*/
|
|
14
14
|
export function appendVary(headers, value) {
|
|
15
15
|
const existing = headers.get('vary');
|
|
@@ -28,8 +28,8 @@ export function appendVary(headers, value) {
|
|
|
28
28
|
* exact body and should be answered with a 304.
|
|
29
29
|
*
|
|
30
30
|
* The header carries a *list*, and each entry may be weak (`W/"…"`). The weak prefix is ignored on
|
|
31
|
-
* both sides
|
|
32
|
-
*
|
|
31
|
+
* both sides: a proxy or CDN that gzips on the way out changes the bytes without changing the
|
|
32
|
+
* representation, and is entitled to weaken the validator when it does.
|
|
33
33
|
*/
|
|
34
34
|
export function etagMatches(ifNoneMatch, etag) {
|
|
35
35
|
if (!ifNoneMatch)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/server/headers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,KAAa;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG;QAAE,OAAO;IACpC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IACxG,IAAI,CAAC,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,WAA+B,EAAE,IAAY;IACvE,IAAI,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAC/B,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,SAAS,KAAK,GAAG,IAAI,SAAS,KAAK,MAAM,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Small header utilities shared by the response-header defaults
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/server/headers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,KAAa;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG;QAAE,OAAO;IACpC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IACxG,IAAI,CAAC,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,WAA+B,EAAE,IAAY;IACvE,IAAI,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAC/B,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,SAAS,KAAK,GAAG,IAAI,SAAS,KAAK,MAAM,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Small header utilities shared by the response-header defaults and the prerendered-page cache. Kept\n * apart from both because getting `Vary` and `ETag` comparison subtly wrong is exactly the kind of\n * thing that only shows up behind a CDN.\n */\n\n/**\n * Adds `value` to the `Vary` header without discarding what is already there.\n *\n * `Vary` is a list, and the framework's own entry (`Accept` — an HTML document or a flight payload from\n * one URL) is not necessarily the only one: a route, a middleware or a proxy may have added its own.\n * A plain `set` would drop the others, and a cache would then serve one variant in place of another.\n * `*` is left alone: it already means \"never reuse this\".\n */\nexport function appendVary(headers: Headers, value: string): void {\n const existing = headers.get('vary');\n if (existing === null) {\n headers.set('vary', value);\n return;\n }\n if (existing.trim() === '*') return;\n const already = existing.split(',').some((entry) => entry.trim().toLowerCase() === value.toLowerCase());\n if (!already) headers.set('vary', `${existing}, ${value}`);\n}\n\n/**\n * True when an `If-None-Match` request header matches `etag`, i.e. the client already holds this\n * exact body and should be answered with a 304.\n *\n * The header carries a *list*, and each entry may be weak (`W/\"…\"`). The weak prefix is ignored on\n * both sides: a proxy or CDN that gzips on the way out changes the bytes without changing the\n * representation, and is entitled to weaken the validator when it does.\n */\nexport function etagMatches(ifNoneMatch: string | undefined, etag: string): boolean {\n if (!ifNoneMatch) return false;\n const normalize = (value: string) => value.trim().replace(/^W\\//, '');\n const wanted = normalize(etag);\n return ifNoneMatch.split(',').some((entry) => {\n const candidate = normalize(entry);\n return candidate === '*' || candidate === wanted;\n });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RshonoConfig } from '../config.js';
|
|
2
2
|
/**
|
|
3
3
|
* Load the project config, or `{}` if none exists. Scans `rshono.config.{ts,js,mjs}` at
|
|
4
4
|
* {@link rootDir} unless an explicit {@link configPath} is given (resolved relative to `cwd`).
|
|
5
5
|
*/
|
|
6
|
-
export declare function loadConfig(rootDir: string, configPath?: string): Promise<
|
|
6
|
+
export declare function loadConfig(rootDir: string, configPath?: string): Promise<RshonoConfig>;
|
|
7
7
|
//# sourceMappingURL=load-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/server/load-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAmBjD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/server/load-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAmBjD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CA6B5F"}
|
|
@@ -5,17 +5,16 @@ const CONFIG_FILES = ['rshono.config.ts', 'rshono.config.js', 'rshono.config.mjs
|
|
|
5
5
|
/**
|
|
6
6
|
* Imports the config module.
|
|
7
7
|
*
|
|
8
|
-
* A `.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* A `.ts` config needs no loader of its own: Node strips types natively from 22.18 on, which is what
|
|
9
|
+
* the package's `engines` floor is for. That replaced a `tsx` dependency whose only job was these two
|
|
10
|
+
* lines — and `tsx` bundles esbuild, so it was the largest thing in the install.
|
|
11
|
+
*
|
|
12
|
+
* The one thing native stripping will not do is resolve a `.js` specifier to a `.ts` file, so a config
|
|
13
|
+
* that imports a sibling module has to name it with its real extension. {@link loadConfig} turns the
|
|
14
|
+
* resulting resolution failure into that advice rather than letting a raw `ERR_MODULE_NOT_FOUND` out.
|
|
12
15
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!/\.[cm]?ts$/.test(file))
|
|
16
|
-
return import(href);
|
|
17
|
-
const { tsImport } = await import('tsx/esm/api');
|
|
18
|
-
return tsImport(href, import.meta.url);
|
|
16
|
+
function importConfig(file) {
|
|
17
|
+
return import(pathToFileURL(file).href);
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* Load the project config, or `{}` if none exists. Scans `rshono.config.{ts,js,mjs}` at
|
|
@@ -32,7 +31,19 @@ export async function loadConfig(rootDir, configPath) {
|
|
|
32
31
|
if (!existsSync(file)) {
|
|
33
32
|
throw new Error(`[rshono] config file not found: ${file}`);
|
|
34
33
|
}
|
|
35
|
-
|
|
34
|
+
let mod;
|
|
35
|
+
try {
|
|
36
|
+
mod = await importConfig(file);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// The one failure mode native type stripping has that a TypeScript-aware loader does not.
|
|
40
|
+
if (/\.[cm]?ts$/.test(file) && error?.code === 'ERR_MODULE_NOT_FOUND') {
|
|
41
|
+
throw new Error(`[rshono] ${file} imports a module Node could not resolve: ${error.message}\n` +
|
|
42
|
+
' A .ts config is loaded by Node itself, which does not rewrite a .js specifier to the .ts file ' +
|
|
43
|
+
'beside it. Import it by its real extension, or move the config to rshono.config.mjs.', { cause: error });
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
36
47
|
if (!mod.default) {
|
|
37
48
|
throw new Error(`[rshono] ${file} must \`export default\` a config object (use \`defineConfig({ … })\`).`);
|
|
38
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../src/server/load-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,YAAY,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;AAEnF
|
|
1
|
+
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../src/server/load-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,YAAY,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;AAEnF;;;;;;;;;;GAUG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAwC,CAAC;AACjF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe,EAAE,UAAmB;IACnE,MAAM,IAAI,GAAG,UAAU;QACrB,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;YACtB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC;QACtC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,GAA+B,CAAC;IACpC,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0FAA0F;QAC1F,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAK,KAAkC,EAAE,IAAI,KAAK,sBAAsB,EAAE,CAAC;YACpG,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,6CAA8C,KAAe,CAAC,OAAO,IAAI;gBACvF,kGAAkG;gBAClG,sFAAsF,EACxF,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,yEAAyE,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC","sourcesContent":["import { existsSync } from 'node:fs';\nimport { isAbsolute, join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RshonoConfig } from '../config.js';\n\nconst CONFIG_FILES = ['rshono.config.ts', 'rshono.config.js', 'rshono.config.mjs'];\n\n/**\n * Imports the config module.\n *\n * A `.ts` config needs no loader of its own: Node strips types natively from 22.18 on, which is what\n * the package's `engines` floor is for. That replaced a `tsx` dependency whose only job was these two\n * lines — and `tsx` bundles esbuild, so it was the largest thing in the install.\n *\n * The one thing native stripping will not do is resolve a `.js` specifier to a `.ts` file, so a config\n * that imports a sibling module has to name it with its real extension. {@link loadConfig} turns the\n * resulting resolution failure into that advice rather than letting a raw `ERR_MODULE_NOT_FOUND` out.\n */\nfunction importConfig(file: string): Promise<{ default?: RshonoConfig }> {\n return import(pathToFileURL(file).href) as Promise<{ default?: RshonoConfig }>;\n}\n\n/**\n * Load the project config, or `{}` if none exists. Scans `rshono.config.{ts,js,mjs}` at\n * {@link rootDir} unless an explicit {@link configPath} is given (resolved relative to `cwd`).\n */\nexport async function loadConfig(rootDir: string, configPath?: string): Promise<RshonoConfig> {\n const file = configPath\n ? isAbsolute(configPath)\n ? configPath\n : resolve(process.cwd(), configPath)\n : CONFIG_FILES.map((f) => join(rootDir, f)).find(existsSync);\n if (!file) return {};\n if (!existsSync(file)) {\n throw new Error(`[rshono] config file not found: ${file}`);\n }\n let mod: { default?: RshonoConfig };\n try {\n mod = await importConfig(file);\n } catch (error) {\n // The one failure mode native type stripping has that a TypeScript-aware loader does not.\n if (/\\.[cm]?ts$/.test(file) && (error as { code?: string } | null)?.code === 'ERR_MODULE_NOT_FOUND') {\n throw new Error(\n `[rshono] ${file} imports a module Node could not resolve: ${(error as Error).message}\\n` +\n ' A .ts config is loaded by Node itself, which does not rewrite a .js specifier to the .ts file ' +\n 'beside it. Import it by its real extension, or move the config to rshono.config.mjs.',\n { cause: error },\n );\n }\n throw error;\n }\n if (!mod.default) {\n throw new Error(`[rshono] ${file} must \\`export default\\` a config object (use \\`defineConfig({ … })\\`).`);\n }\n return mod.default;\n}\n"]}
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* it from the fs module would drag `node:fs` and `node:crypto` into a bundle that has neither.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
-
* The two representations of a page, prerendered side by side
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Writing only the HTML meant every in-app click re-rendered a page that was already built, so the
|
|
14
|
-
* prerender only ever paid off for cold loads and crawlers.
|
|
10
|
+
* The two representations of a page, prerendered side by side: a hard load wants the HTML document, a
|
|
11
|
+
* soft navigation asks the same URL for a flight payload. Without both, every in-app click would
|
|
12
|
+
* re-render a page that was already built.
|
|
15
13
|
*/
|
|
16
14
|
export type PrerenderVariant = 'html' | 'flight';
|
|
17
15
|
export declare const VARIANTS: {
|
|
@@ -42,25 +40,55 @@ export declare function ssgFilePath(routePath: string, variant?: PrerenderVarian
|
|
|
42
40
|
* fall back on, so `..` has to be refused here or not at all.
|
|
43
41
|
*/
|
|
44
42
|
export declare function prerenderedRelPath(requestPath: string, variant: PrerenderVariant): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* A bounded, insertion-ordered cache of prerendered pages.
|
|
45
|
+
*
|
|
46
|
+
* Bounded so a site with thousands of prerendered pages keeps a working set rather than the whole
|
|
47
|
+
* build in memory. Only *hits* are ever stored: caching misses would let anyone mint entries by
|
|
48
|
+
* requesting paths that don't exist. The files are written at build time and never change while the
|
|
49
|
+
* server is up, so an entry never needs invalidating.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createPageCache(max?: number): {
|
|
52
|
+
get(key: string): PrerenderedPage | undefined;
|
|
53
|
+
set(key: string, page: PrerenderedPage): void;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A weak `ETag` for a page body — see {@link PrerenderedPage.etag} for why weak.
|
|
57
|
+
*
|
|
58
|
+
* Web Crypto rather than `node:crypto`, so the one implementation serves both a Node server and
|
|
59
|
+
* `workerd`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function weakEtag(body: Uint8Array<ArrayBuffer>): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Assembles a {@link PrerenderedPage} from a body just read out of the build.
|
|
64
|
+
*
|
|
65
|
+
* `storeEtag` is the validator the store supplied, where it has one — it already describes these
|
|
66
|
+
* exact bytes, so it is preferred over hashing them again, and only weakened.
|
|
67
|
+
*/
|
|
68
|
+
export declare function toPrerenderedPage(body: Uint8Array<ArrayBuffer>, storeEtag?: string | null): Promise<PrerenderedPage>;
|
|
45
69
|
/** A prerendered page, ready to serve: its body and a validator derived from those exact bytes. */
|
|
46
70
|
export interface PrerenderedPage {
|
|
47
|
-
/** The document or the flight payload, depending on which {@link PrerenderVariant} was read. */
|
|
48
|
-
body: string;
|
|
49
71
|
/**
|
|
50
|
-
*
|
|
72
|
+
* The document or the flight payload, depending on which {@link PrerenderVariant} was read.
|
|
51
73
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
74
|
+
* Bytes rather than a string, because this is a *cache* entry served verbatim to every request that
|
|
75
|
+
* hits it — held as a string, each of those would pay a fresh UTF-8 encode of the whole page on the
|
|
76
|
+
* way out. Read once, encoded never.
|
|
77
|
+
*/
|
|
78
|
+
body: Uint8Array<ArrayBuffer>;
|
|
79
|
+
/**
|
|
80
|
+
* `Content-Length` for {@link body}, in bytes rather than characters. Served explicitly because
|
|
81
|
+
* Hono sets no length for an in-memory body, and a proxy or CDN in front is entitled to make
|
|
82
|
+
* decisions with it — whether gzipping this response is worth the framing, most obviously.
|
|
55
83
|
*/
|
|
56
84
|
contentLength: string;
|
|
57
85
|
/**
|
|
58
86
|
* `ETag` for the page, so a revalidating client can be answered with a 304 instead of the body.
|
|
59
87
|
*
|
|
60
|
-
* Deliberately **weak**. The bytes on the wire depend on whether
|
|
61
|
-
* strong validator would have to differ
|
|
62
|
-
* revalidates it
|
|
63
|
-
*
|
|
88
|
+
* Deliberately **weak**. The bytes on the wire depend on whether something in front re-encoded
|
|
89
|
+
* them, and a strong validator would have to differ per coding — so the 200 and the 304 that
|
|
90
|
+
* revalidates it could disagree, and a cache would treat them as different pages. A weak tag says
|
|
91
|
+
* "the same representation", which is what stays true across content codings.
|
|
64
92
|
*/
|
|
65
93
|
etag: string;
|
|
66
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerendered.d.ts","sourceRoot":"","sources":["../../src/server/prerendered.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH
|
|
1
|
+
{"version":3,"file":"prerendered.d.ts","sourceRoot":"","sources":["../../src/server/prerendered.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjD,eAAO,MAAM,QAAQ;;iBACX,IAAI,EAAE,YAAY;iBAAE,MAAM,EAAE,WAAW;iBAAE,WAAW,EAAE,WAAW;;;iBAC/D,IAAI,EAAE,WAAW;iBAAE,MAAM,EAAE,kBAAkB;iBAAE,WAAW,EAAE,kBAAkB;;CACU,CAAC;AAErG;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAyB,GAAG,MAAM,GAAG,IAAI,CAKhG;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAGhG;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,GAAG,SAAM,GAAG;IAAE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,CAU3I;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAO7E;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAM1H;AAED,mGAAmG;AACnG,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC9B;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -36,4 +36,51 @@ export function prerenderedRelPath(requestPath, variant) {
|
|
|
36
36
|
return null;
|
|
37
37
|
return ssgFilePath(requestPath, variant);
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A bounded, insertion-ordered cache of prerendered pages.
|
|
41
|
+
*
|
|
42
|
+
* Bounded so a site with thousands of prerendered pages keeps a working set rather than the whole
|
|
43
|
+
* build in memory. Only *hits* are ever stored: caching misses would let anyone mint entries by
|
|
44
|
+
* requesting paths that don't exist. The files are written at build time and never change while the
|
|
45
|
+
* server is up, so an entry never needs invalidating.
|
|
46
|
+
*/
|
|
47
|
+
export function createPageCache(max = 128) {
|
|
48
|
+
const pages = new Map();
|
|
49
|
+
return {
|
|
50
|
+
get: (key) => pages.get(key),
|
|
51
|
+
set(key, page) {
|
|
52
|
+
pages.set(key, page);
|
|
53
|
+
// Insertion-ordered, so the first key is the oldest. One entry in means at most one out.
|
|
54
|
+
if (pages.size > max)
|
|
55
|
+
pages.delete(pages.keys().next().value);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A weak `ETag` for a page body — see {@link PrerenderedPage.etag} for why weak.
|
|
61
|
+
*
|
|
62
|
+
* Web Crypto rather than `node:crypto`, so the one implementation serves both a Node server and
|
|
63
|
+
* `workerd`.
|
|
64
|
+
*/
|
|
65
|
+
export async function weakEtag(body) {
|
|
66
|
+
const digest = await crypto.subtle.digest('SHA-256', body);
|
|
67
|
+
const base64url = btoa(String.fromCharCode(...new Uint8Array(digest)))
|
|
68
|
+
.replace(/\+/g, '-')
|
|
69
|
+
.replace(/\//g, '_')
|
|
70
|
+
.replace(/=+$/, '');
|
|
71
|
+
return `W/"${base64url.slice(0, 22)}"`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Assembles a {@link PrerenderedPage} from a body just read out of the build.
|
|
75
|
+
*
|
|
76
|
+
* `storeEtag` is the validator the store supplied, where it has one — it already describes these
|
|
77
|
+
* exact bytes, so it is preferred over hashing them again, and only weakened.
|
|
78
|
+
*/
|
|
79
|
+
export async function toPrerenderedPage(body, storeEtag) {
|
|
80
|
+
return {
|
|
81
|
+
body,
|
|
82
|
+
contentLength: String(body.byteLength),
|
|
83
|
+
etag: storeEtag ? storeEtag.replace(/^(?!W\/)/, 'W/') : await weakEtag(body),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
39
86
|
//# sourceMappingURL=prerendered.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerendered.js","sourceRoot":"","sources":["../../src/server/prerendered.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"prerendered.js","sourceRoot":"","sources":["../../src/server/prerendered.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE;IAC3E,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,kBAAkB,EAAE;CACQ,CAAC;AAErG;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,OAAO,GAAqB,MAAM;IAC/E,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IACpC,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB,EAAE,OAAyB;IAC/E,IAAI,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC;QAAE,OAAO,IAAI,CAAC;IACvD,OAAO,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,GAAG,GAAG,GAAG;IACvC,MAAM,KAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;IACjD,OAAO;QACL,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;QAC5B,GAAG,CAAC,GAAG,EAAE,IAAI;YACX,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACrB,yFAAyF;YACzF,IAAI,KAAK,CAAC,IAAI,GAAG,GAAG;gBAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAM,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAA6B;IAC1D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;SACnE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACtB,OAAO,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAA6B,EAAE,SAAyB;IAC9F,OAAO;QACL,IAAI;QACJ,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;QACtC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC;KAC7E,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Everything about a prerendered page that doesn't need a filesystem: where the build puts it, and\n * what it looks like once read back.\n *\n * Split out of `ssg.ts` — which owns the writing and the reading, both through `node:fs` — because a\n * deploy target without a filesystem reads the very same layout out of an asset store, and importing\n * it from the fs module would drag `node:fs` and `node:crypto` into a bundle that has neither.\n */\n\n/**\n * The two representations of a page, prerendered side by side: a hard load wants the HTML document, a\n * soft navigation asks the same URL for a flight payload. Without both, every in-app click would\n * re-render a page that was already built.\n */\nexport type PrerenderVariant = 'html' | 'flight';\n\nexport const VARIANTS = {\n html: { file: 'index.html', accept: 'text/html', contentType: 'text/html' },\n flight: { file: 'index.rsc', accept: 'text/x-component', contentType: 'text/x-component' },\n} as const satisfies Record<PrerenderVariant, { file: string; accept: string; contentType: string }>;\n\n/**\n * Where a route's prerendered output lives, relative to the output root — or `null` for a path that\n * cannot be prerendered at all (one with a param or a wildcard left in it).\n *\n * Always `/`-separated, never the host's separator: the same string addresses a file on a filesystem\n * (`resolve()` and `join()` both accept forward slashes on Windows) and a key in an asset store,\n * where a backslash would simply be the wrong character.\n */\nexport function ssgFilePath(routePath: string, variant: PrerenderVariant = 'html'): string | null {\n if (/[:*]/.test(routePath)) return null;\n const trimmed = routePath.replace(/^\\/+|\\/+$/g, '');\n const file = VARIANTS[variant].file;\n return trimmed === '' ? file : `${trimmed}/${file}`;\n}\n\n/**\n * {@link ssgFilePath} for a path that came off a request, so traversal is a miss rather than a lookup.\n *\n * The first line of defence for every deploy target: a store addressed by key has no `resolve()` to\n * fall back on, so `..` has to be refused here or not at all.\n */\nexport function prerenderedRelPath(requestPath: string, variant: PrerenderVariant): string | null {\n if (/(^|\\/)\\.\\.?(\\/|$)/.test(requestPath)) return null;\n return ssgFilePath(requestPath, variant);\n}\n\n/**\n * A bounded, insertion-ordered cache of prerendered pages.\n *\n * Bounded so a site with thousands of prerendered pages keeps a working set rather than the whole\n * build in memory. Only *hits* are ever stored: caching misses would let anyone mint entries by\n * requesting paths that don't exist. The files are written at build time and never change while the\n * server is up, so an entry never needs invalidating.\n */\nexport function createPageCache(max = 128): { get(key: string): PrerenderedPage | undefined; set(key: string, page: PrerenderedPage): void } {\n const pages = new Map<string, PrerenderedPage>();\n return {\n get: (key) => pages.get(key),\n set(key, page) {\n pages.set(key, page);\n // Insertion-ordered, so the first key is the oldest. One entry in means at most one out.\n if (pages.size > max) pages.delete(pages.keys().next().value!);\n },\n };\n}\n\n/**\n * A weak `ETag` for a page body — see {@link PrerenderedPage.etag} for why weak.\n *\n * Web Crypto rather than `node:crypto`, so the one implementation serves both a Node server and\n * `workerd`.\n */\nexport async function weakEtag(body: Uint8Array<ArrayBuffer>): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-256', body);\n const base64url = btoa(String.fromCharCode(...new Uint8Array(digest)))\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+$/, '');\n return `W/\"${base64url.slice(0, 22)}\"`;\n}\n\n/**\n * Assembles a {@link PrerenderedPage} from a body just read out of the build.\n *\n * `storeEtag` is the validator the store supplied, where it has one — it already describes these\n * exact bytes, so it is preferred over hashing them again, and only weakened.\n */\nexport async function toPrerenderedPage(body: Uint8Array<ArrayBuffer>, storeEtag?: string | null): Promise<PrerenderedPage> {\n return {\n body,\n contentLength: String(body.byteLength),\n etag: storeEtag ? storeEtag.replace(/^(?!W\\/)/, 'W/') : await weakEtag(body),\n };\n}\n\n/** A prerendered page, ready to serve: its body and a validator derived from those exact bytes. */\nexport interface PrerenderedPage {\n /**\n * The document or the flight payload, depending on which {@link PrerenderVariant} was read.\n *\n * Bytes rather than a string, because this is a *cache* entry served verbatim to every request that\n * hits it — held as a string, each of those would pay a fresh UTF-8 encode of the whole page on the\n * way out. Read once, encoded never.\n */\n body: Uint8Array<ArrayBuffer>;\n /**\n * `Content-Length` for {@link body}, in bytes rather than characters. Served explicitly because\n * Hono sets no length for an in-memory body, and a proxy or CDN in front is entitled to make\n * decisions with it — whether gzipping this response is worth the framing, most obviously.\n */\n contentLength: string;\n /**\n * `ETag` for the page, so a revalidating client can be answered with a 304 instead of the body.\n *\n * Deliberately **weak**. The bytes on the wire depend on whether something in front re-encoded\n * them, and a strong validator would have to differ per coding — so the 200 and the 304 that\n * revalidates it could disagree, and a cache would treat them as different pages. A weak tag says\n * \"the same representation\", which is what stays true across content codings.\n */\n etag: string;\n}\n"]}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RshonoConfig } from '../config.js';
|
|
2
2
|
/**
|
|
3
|
-
* The framework settings the server bundle needs at request time, fully resolved
|
|
4
|
-
* (defaults applied, `bodySizeLimit` parsed to bytes, origins normalized to hosts).
|
|
3
|
+
* The framework settings the server bundle needs at request time, fully resolved.
|
|
5
4
|
*
|
|
6
5
|
* The value is produced once by {@link resolveServerConfig} from `rshono.config.ts`
|
|
7
6
|
* and compiled into the server bundle as the `__RSHONO_CONFIG__` literal (see
|
|
8
7
|
* `builder/rspack-config.ts`) — there is no runtime env-var interface for these.
|
|
8
|
+
*
|
|
9
|
+
* Only two fields, because only two things here are decided by the *build*. The per-request
|
|
10
|
+
* security controls that used to live alongside them — the CSRF check, the CSP, the body cap — are
|
|
11
|
+
* Hono middleware an app registers in `src/server.ts`, where they can be configured per route and
|
|
12
|
+
* per environment instead of once per bundle.
|
|
9
13
|
*/
|
|
10
14
|
export interface ServerConfig {
|
|
11
15
|
/**
|
|
@@ -15,58 +19,28 @@ export interface ServerConfig {
|
|
|
15
19
|
* produced the bundle, and a deploy target need not have a `process` to read it from.
|
|
16
20
|
*/
|
|
17
21
|
isDev: boolean;
|
|
18
|
-
/** Deadline in ms for a single request (server action + flight + SSR). */
|
|
19
|
-
renderTimeoutMs: number;
|
|
20
22
|
/** Honour `X-Forwarded-Host` / `-Proto` when resolving the browser-facing URL. Forced on in dev. */
|
|
21
23
|
trustProxy: boolean;
|
|
22
|
-
/** Send a strict per-request-nonce Content-Security-Policy with every HTML document. */
|
|
23
|
-
cspEnabled: boolean;
|
|
24
|
-
/** The resolved CSP directives (built-in defaults with the user's merged over them), minus the nonce. */
|
|
25
|
-
cspDirectives: Record<string, string>;
|
|
26
|
-
/** CSRF origin check on server-action POSTs. */
|
|
27
|
-
checkOrigin: boolean;
|
|
28
|
-
/** Extra origins allowed to post server actions, normalized to lowercase `URL.host` values. */
|
|
29
|
-
allowedOrigins: string[];
|
|
30
|
-
/** Max request body in bytes before a 413; `0` disables the cap. */
|
|
31
|
-
maxBodyBytes: number;
|
|
32
|
-
/** Gzip compressible responses on the way out. */
|
|
33
|
-
compress: boolean;
|
|
34
|
-
/** Default listen port for `start` (overridden by `PORT`). */
|
|
35
|
-
port?: number;
|
|
36
|
-
/** Default bind address for `start` (overridden by `HOST`). */
|
|
37
|
-
host?: string;
|
|
38
24
|
}
|
|
39
25
|
/**
|
|
40
|
-
* The
|
|
26
|
+
* The framework's built-in defaults.
|
|
41
27
|
*
|
|
42
|
-
* `
|
|
43
|
-
*
|
|
44
|
-
*
|
|
28
|
+
* `port` and `host` are not config fields at all — they come from `PORT` / `HOST` (or `--port`)
|
|
29
|
+
* wherever the address is resolved, `deploy/node/runtime.ts` for a server bundle and `cli/dev.ts`
|
|
30
|
+
* for the dev server, and this is what both fall back to.
|
|
45
31
|
*/
|
|
46
32
|
export declare const SERVER_DEFAULTS: {
|
|
47
|
-
readonly renderTimeoutMs: 10000;
|
|
48
|
-
readonly maxBodyBytes: number;
|
|
49
33
|
readonly port: 3000;
|
|
50
34
|
readonly host: '0.0.0.0';
|
|
51
35
|
};
|
|
52
36
|
/**
|
|
53
|
-
*
|
|
54
|
-
* {@link RSHonoConfig.cspDirectives} can override entries individually.
|
|
55
|
-
*
|
|
56
|
-
* `script-src` carries the per-request nonce, appended at request time (see `entry.rsc.tsx`).
|
|
57
|
-
* `style-src` needs `'unsafe-inline'` because React writes inline styles.
|
|
58
|
-
*/
|
|
59
|
-
export declare const CSP_DEFAULTS: Record<string, string>;
|
|
60
|
-
/** Parse a {@link RSHonoConfig.bodySizeLimit} value into a byte count (`false`/`0` → `0`, disabling the cap). */
|
|
61
|
-
export declare function parseByteSize(value: string | number | false | undefined): number | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Resolve the user's {@link RSHonoConfig} into the {@link ServerConfig} baked into the bundle.
|
|
37
|
+
* Resolve the user's {@link RshonoConfig} into the {@link ServerConfig} baked into the bundle.
|
|
64
38
|
*
|
|
65
39
|
* `isDev` is a build-time input rather than a config field because it decides one thing the user
|
|
66
40
|
* shouldn't have to: `trustProxy` is forced on under `rshono dev`, where the framework's own proxy
|
|
67
41
|
* is the only way in (it sets the forwarded headers itself and binds to localhost).
|
|
68
42
|
*/
|
|
69
|
-
export declare function resolveServerConfig(config:
|
|
43
|
+
export declare function resolveServerConfig(config: RshonoConfig, { isDev }: {
|
|
70
44
|
isDev: boolean;
|
|
71
45
|
}): ServerConfig;
|
|
72
46
|
//# sourceMappingURL=server-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-config.d.ts","sourceRoot":"","sources":["../../src/server/server-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"server-config.d.ts","sourceRoot":"","sources":["../../src/server/server-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAC;IACf,oGAAoG;IACpG,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;aAC1B,IAAI,EAAE,IAAI;aACV,IAAI,EAAE,SAAS;CACP,CAAC;AAEX;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,YAAY,CAKrG"}
|
|
@@ -1,73 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The framework's built-in defaults.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `port` and `host` are not config fields at all — they come from `PORT` / `HOST` (or `--port`)
|
|
5
|
+
* wherever the address is resolved, `deploy/node/runtime.ts` for a server bundle and `cli/dev.ts`
|
|
6
|
+
* for the dev server, and this is what both fall back to.
|
|
7
7
|
*/
|
|
8
8
|
export const SERVER_DEFAULTS = {
|
|
9
|
-
renderTimeoutMs: 10_000,
|
|
10
|
-
maxBodyBytes: 1024 * 1024, // 1 MiB, matching Next.js's server-action body-size limit.
|
|
11
9
|
port: 3000,
|
|
12
10
|
host: '0.0.0.0',
|
|
13
11
|
};
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
16
|
-
* {@link RSHonoConfig.cspDirectives} can override entries individually.
|
|
17
|
-
*
|
|
18
|
-
* `script-src` carries the per-request nonce, appended at request time (see `entry.rsc.tsx`).
|
|
19
|
-
* `style-src` needs `'unsafe-inline'` because React writes inline styles.
|
|
20
|
-
*/
|
|
21
|
-
export const CSP_DEFAULTS = {
|
|
22
|
-
'default-src': "'self'",
|
|
23
|
-
'script-src': "'self'",
|
|
24
|
-
'style-src': "'self' 'unsafe-inline'",
|
|
25
|
-
'img-src': "'self' data:",
|
|
26
|
-
'connect-src': "'self'",
|
|
27
|
-
// Not covered by default-src, and each closes an injection route of its own: a stray <base>
|
|
28
|
-
// retargeting every relative URL, plugin content, framing (clickjacking), off-site form posts.
|
|
29
|
-
'base-uri': "'self'",
|
|
30
|
-
'object-src': "'none'",
|
|
31
|
-
'frame-ancestors': "'none'",
|
|
32
|
-
'form-action': "'self'",
|
|
33
|
-
};
|
|
34
|
-
const UNITS = { b: 1, kb: 1024, mb: 1024 ** 2, gb: 1024 ** 3 };
|
|
35
|
-
/** Parse a {@link RSHonoConfig.bodySizeLimit} value into a byte count (`false`/`0` → `0`, disabling the cap). */
|
|
36
|
-
export function parseByteSize(value) {
|
|
37
|
-
if (value === undefined)
|
|
38
|
-
return undefined;
|
|
39
|
-
if (value === false)
|
|
40
|
-
return 0;
|
|
41
|
-
if (typeof value === 'number')
|
|
42
|
-
return value;
|
|
43
|
-
const match = /^\s*(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?\s*$/i.exec(value);
|
|
44
|
-
if (!match) {
|
|
45
|
-
throw new Error(`[rshono] invalid bodySizeLimit ${JSON.stringify(value)} — use e.g. '1mb', 1048576, or false.`);
|
|
46
|
-
}
|
|
47
|
-
return Math.floor(Number(match[1]) * UNITS[(match[2] ?? 'b').toLowerCase()]);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Normalize a config `allowedOrigins` entry (full origin or bare host) to a lowercase `URL.host`,
|
|
51
|
-
* ready for a direct comparison against a parsed `Origin` header's host.
|
|
52
|
-
*
|
|
53
|
-
* A bare `host:port` has to be retried against a base, because on its own `'localhost:4000'`
|
|
54
|
-
* parses as the *scheme* `localhost:` with path `4000` — leaving an empty host that would
|
|
55
|
-
* silently never match anything. Throws rather than passing a junk entry through, so a typo
|
|
56
|
-
* fails the build instead of quietly disabling the allowlist entry it was meant to add.
|
|
57
|
-
*/
|
|
58
|
-
function normalizeOrigin(entry) {
|
|
59
|
-
const host = URL.parse(entry)?.host || URL.parse(`http://${entry}`)?.host;
|
|
60
|
-
if (!host) {
|
|
61
|
-
throw new Error(`[rshono] invalid allowedOrigins entry ${JSON.stringify(entry)} — use a full origin ('https://admin.example.com') or a bare host ('localhost:4000').`);
|
|
62
|
-
}
|
|
63
|
-
return host.toLowerCase();
|
|
64
|
-
}
|
|
65
|
-
/** Drop directives the user blanked out, so `cspDirectives: { 'frame-ancestors': '' }` removes one. */
|
|
66
|
-
function resolveCspDirectives(overrides) {
|
|
67
|
-
return Object.fromEntries(Object.entries({ ...CSP_DEFAULTS, ...overrides }).filter(([, value]) => value.trim() !== ''));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Resolve the user's {@link RSHonoConfig} into the {@link ServerConfig} baked into the bundle.
|
|
13
|
+
* Resolve the user's {@link RshonoConfig} into the {@link ServerConfig} baked into the bundle.
|
|
71
14
|
*
|
|
72
15
|
* `isDev` is a build-time input rather than a config field because it decides one thing the user
|
|
73
16
|
* shouldn't have to: `trustProxy` is forced on under `rshono dev`, where the framework's own proxy
|
|
@@ -76,19 +19,7 @@ function resolveCspDirectives(overrides) {
|
|
|
76
19
|
export function resolveServerConfig(config, { isDev }) {
|
|
77
20
|
return {
|
|
78
21
|
isDev,
|
|
79
|
-
renderTimeoutMs: config.renderTimeout ?? SERVER_DEFAULTS.renderTimeoutMs,
|
|
80
22
|
trustProxy: isDev || (config.trustProxy ?? false),
|
|
81
|
-
cspEnabled: config.csp ?? false,
|
|
82
|
-
cspDirectives: resolveCspDirectives(config.cspDirectives),
|
|
83
|
-
checkOrigin: config.checkOrigin ?? true,
|
|
84
|
-
allowedOrigins: (config.allowedOrigins ?? [])
|
|
85
|
-
.map((entry) => entry.trim())
|
|
86
|
-
.filter(Boolean)
|
|
87
|
-
.map(normalizeOrigin),
|
|
88
|
-
maxBodyBytes: parseByteSize(config.bodySizeLimit) ?? SERVER_DEFAULTS.maxBodyBytes,
|
|
89
|
-
compress: config.compress ?? true,
|
|
90
|
-
port: config.port,
|
|
91
|
-
host: config.host,
|
|
92
23
|
};
|
|
93
24
|
}
|
|
94
25
|
//# sourceMappingURL=server-config.js.map
|