fondu 0.16.0 → 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.
- package/README.md +12 -0
- package/dist/client/app.js +21 -1
- package/dist/server/app.d.ts +8 -3
- package/dist/server/app.js +15 -10
- package/dist/server/document.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,6 +31,18 @@ on Cloudflare Workers with D1 and Better Auth.
|
|
|
31
31
|
server and client code, server-side rendering, static pages, MDX pages, internationalization, deploying, and the API.
|
|
32
32
|
Every page is also Markdown for coding agents ([llms.txt](https://fondu.dev/llms.txt)).
|
|
33
33
|
|
|
34
|
+
## For coding agents
|
|
35
|
+
|
|
36
|
+
Fondu's rules for an app (routes, pages, forms, navigation, data, rendering, the server, types) are an agent skill,
|
|
37
|
+
[`skills/fondu/`](https://github.com/fondujs/fondu/tree/main/skills/fondu), kept here with the code it describes. Install it in an app with the
|
|
38
|
+
[`skills`](https://github.com/vercel-labs/skills) CLI:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx skills add fondujs/fondu
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
An app's `AGENTS.md` then says only what is the app's own.
|
|
45
|
+
|
|
34
46
|
## Contributing
|
|
35
47
|
|
|
36
48
|
```
|
package/dist/client/app.js
CHANGED
|
@@ -68,7 +68,27 @@ class Failed extends Component {
|
|
|
68
68
|
render() {
|
|
69
69
|
if (!this.state.failed)
|
|
70
70
|
return this.props.children;
|
|
71
|
-
return ErrorPage
|
|
71
|
+
return ErrorPage
|
|
72
|
+
? createElement(Unfailing, null, createElement(ErrorPage, { status: 500 }))
|
|
73
|
+
: PLAIN;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const PLAIN = 'Something went wrong';
|
|
77
|
+
/**
|
|
78
|
+
* The error page's own boundary: `Failed` renders the error page outside its own reach, so an error page that throws
|
|
79
|
+
* would escape every boundary and React would unmount the app (a blank page). Plain text instead, and the error in
|
|
80
|
+
* the console: the app's author must see it.
|
|
81
|
+
*/
|
|
82
|
+
class Unfailing extends Component {
|
|
83
|
+
state = { failed: false };
|
|
84
|
+
static getDerivedStateFromError() {
|
|
85
|
+
return { failed: true };
|
|
86
|
+
}
|
|
87
|
+
componentDidCatch(error) {
|
|
88
|
+
console.error('[fondu] the error page failed to render:', error);
|
|
89
|
+
}
|
|
90
|
+
render() {
|
|
91
|
+
return this.state.failed ? PLAIN : this.props.children;
|
|
72
92
|
}
|
|
73
93
|
}
|
|
74
94
|
/**
|
package/dist/server/app.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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,
|
|
32
|
-
*
|
|
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 {};
|
package/dist/server/app.js
CHANGED
|
@@ -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,
|
|
98
|
-
*
|
|
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/dist/server/document.js
CHANGED
|
@@ -94,6 +94,10 @@ export async function renderDocument(c, page, whole = false) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
catch (error) {
|
|
97
|
+
// the error page's failure goes to `errorResponse`: plain text with the status (the browser would render the
|
|
98
|
+
// same props and most likely fail again, and a visitor without JavaScript would get nothing)
|
|
99
|
+
if (page.component === '_error')
|
|
100
|
+
throw error;
|
|
97
101
|
// like Laravel: a page that fails to render on the server is still sent, and rendered in the browser
|
|
98
102
|
console.error(`[fondu] server render of "${page.component}" failed, sending it to render in the browser:`, error);
|
|
99
103
|
}
|