fondu 0.16.1 → 0.16.2

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.
@@ -9,7 +9,11 @@ export interface CreateAppOptions {
9
9
  trailingSlash?: 'trim' | 'append';
10
10
  /** `hono/csrf`'s options; `false`: off */
11
11
  csrf?: Parameters<typeof csrf>[0] | false;
12
- /** the largest request body, in bytes (default: 10 MB), then 413: `hono/body-limit`; `false`: no limit */
12
+ /**
13
+ * the largest request body, in bytes (default: 10 MB), then 413: `hono/body-limit`; `false`: no limit. The body is
14
+ * read whole, in memory (about twice its size): raise it only a little. A limit by path: `false`, and Hono's
15
+ * `bodyLimit` in the root `_middleware.ts` (docs: Forms, "The body limit")
16
+ */
13
17
  bodyLimit?: number | false;
14
18
  /**
15
19
  * `hono/secure-headers`' options; `false`: off. Defaults: `referrerPolicy: 'same-origin'` (which `back()` needs) and
@@ -28,8 +32,9 @@ export declare function checkExports(file: string, mod: Record<string, unknown>)
28
32
  * - server code, `.ts`: HTTP handlers only, `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS` (not `loader`,
29
33
  * `action`, `actions`: those are a page's)
30
34
  * `_middleware.ts` applies to its directory and below (`routes/_middleware.ts`: every request, 404s included).
31
- * Built in: CSRF protection, security headers, a request body limit, one URL per page (trailing slash), the error
32
- * page. Your own 404 / error handling: Hono's `app.notFound()` / `app.onError()` on the returned app.
35
+ * Built in: CSRF protection, security headers, one URL per page (trailing slash), the error page, and a request body
36
+ * limit (413, after the root `_middleware.ts`, so its error page has the shared props; CSRF's 403 is plain text).
37
+ * Your own 404 / error handling: Hono's `app.notFound()` / `app.onError()` on the returned app.
33
38
  */
34
39
  export declare function createApp(options?: CreateAppOptions): Hono;
35
40
  export {};
@@ -94,8 +94,9 @@ function actionName(url) {
94
94
  * - server code, `.ts`: HTTP handlers only, `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS` (not `loader`,
95
95
  * `action`, `actions`: those are a page's)
96
96
  * `_middleware.ts` applies to its directory and below (`routes/_middleware.ts`: every request, 404s included).
97
- * Built in: CSRF protection, security headers, a request body limit, one URL per page (trailing slash), the error
98
- * page. Your own 404 / error handling: Hono's `app.notFound()` / `app.onError()` on the returned app.
97
+ * Built in: CSRF protection, security headers, one URL per page (trailing slash), the error page, and a request body
98
+ * limit (413, after the root `_middleware.ts`, so its error page has the shared props; CSRF's 403 is plain text).
99
+ * Your own 404 / error handling: Hono's `app.notFound()` / `app.onError()` on the returned app.
99
100
  */
100
101
  export function createApp(options = {}) {
101
102
  const app = new Hono();
@@ -133,14 +134,6 @@ export function createApp(options = {}) {
133
134
  }
134
135
  if (options.csrf !== false)
135
136
  app.use(csrf(options.csrf));
136
- if (options.bodyLimit !== false)
137
- app.use(bodyLimit({
138
- maxSize: options.bodyLimit ?? 10 * 1024 * 1024,
139
- // Fondu's own answer: the error page for a visitor, the status alone for an API client
140
- onError: () => {
141
- throw new HTTPException(413);
142
- },
143
- }));
144
137
  const prerendered = [];
145
138
  if (prerender)
146
139
  prerenderRoutes(app, () => prerendered, version);
@@ -155,6 +148,18 @@ export function createApp(options = {}) {
155
148
  const rootMiddleware = modules['_middleware.ts']?.default;
156
149
  if (rootMiddleware)
157
150
  app.use(...chain(rootMiddleware));
151
+ // After the root middleware, so the error page of a 413 has the shared props it set (a layout reads them). The limit
152
+ // still runs before any body is read: with a Content-Length the header is checked, without one the body is counted
153
+ // as it is read. A root middleware must not read the body itself. CSRF stays above: Hono's 403 has its own plain
154
+ // response, so no page is rendered for it.
155
+ if (options.bodyLimit !== false)
156
+ app.use(bodyLimit({
157
+ maxSize: options.bodyLimit ?? 10 * 1024 * 1024,
158
+ // Fondu's own answer: the error page for a visitor, the status alone for an API client
159
+ onError: () => {
160
+ throw new HTTPException(413);
161
+ },
162
+ }));
158
163
  for (const { file, pattern, path, middleware } of routeTable(modules, append)) {
159
164
  const mod = modules[file];
160
165
  const page = isPageFile(file) ? pageId(file) : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fondu",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "A small meta-framework for full-stack React apps, built on Hono and Vite. It runs on Bun, Cloudflare Workers and Node.",
5
5
  "keywords": [
6
6
  "bun",