netjes 0.0.4 → 0.0.6
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 -8
- package/cli/commands.mjs +94 -15
- package/cli/process-io.mjs +2 -2
- package/cli/scaffold.mjs +89 -8
- package/dist/actions.d.ts +3 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +5 -4
- package/dist/actions.js.map +1 -1
- package/dist/client-entry.js +4 -1
- package/dist/client-entry.js.map +1 -1
- package/dist/document.d.ts +3 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +4 -3
- package/dist/document.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lang.d.ts +10 -0
- package/dist/lang.d.ts.map +1 -0
- package/dist/lang.js +26 -0
- package/dist/lang.js.map +1 -0
- package/dist/link.d.ts +15 -3
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +15 -9
- package/dist/link.js.map +1 -1
- package/dist/locale.d.ts +5 -0
- package/dist/locale.d.ts.map +1 -1
- package/dist/locale.js +4 -0
- package/dist/locale.js.map +1 -1
- package/dist/metadata.d.ts +81 -4
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +129 -7
- package/dist/metadata.js.map +1 -1
- package/dist/modules.d.ts +6 -1
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +15 -1
- package/dist/modules.js.map +1 -1
- package/dist/mounted.d.ts +3 -7
- package/dist/mounted.d.ts.map +1 -1
- package/dist/mounted.js.map +1 -1
- package/dist/navigation-guard.d.ts +59 -0
- package/dist/navigation-guard.d.ts.map +1 -0
- package/dist/navigation-guard.js +116 -0
- package/dist/navigation-guard.js.map +1 -0
- package/dist/offline.d.ts +11 -0
- package/dist/offline.d.ts.map +1 -0
- package/dist/offline.js +98 -0
- package/dist/offline.js.map +1 -0
- package/dist/payload.d.ts +38 -2
- package/dist/payload.d.ts.map +1 -1
- package/dist/payload.js +54 -7
- package/dist/payload.js.map +1 -1
- package/dist/render-document.d.ts +8 -1
- package/dist/render-document.d.ts.map +1 -1
- package/dist/render-document.js +2 -0
- package/dist/render-document.js.map +1 -1
- package/dist/root.d.ts.map +1 -1
- package/dist/root.js +10 -1
- package/dist/root.js.map +1 -1
- package/dist/route-tree.d.ts +2 -1
- package/dist/route-tree.d.ts.map +1 -1
- package/dist/route-tree.js +14 -7
- package/dist/route-tree.js.map +1 -1
- package/dist/router.d.ts +101 -20
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +590 -68
- package/dist/router.js.map +1 -1
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +5 -0
- package/dist/schema.js.map +1 -1
- package/dist/service-worker.d.ts +81 -0
- package/dist/service-worker.d.ts.map +1 -0
- package/dist/service-worker.js +584 -0
- package/dist/service-worker.js.map +1 -0
- package/dist/testing.d.ts +18 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +63 -22
- package/dist/testing.js.map +1 -1
- package/package.json +16 -5
- package/sidecar/server.mjs +105 -16
- package/skills/netjes/SKILL.md +5 -3
- package/skills/netjes/references/caching-and-streaming.md +22 -1
- package/skills/netjes/references/data-and-actions.md +5 -4
- package/skills/netjes/references/deployment.md +3 -3
- package/skills/netjes/references/routing.md +14 -6
- package/skills/netjes/references/testing.md +6 -3
- package/src/actions.tsx +5 -4
- package/src/client-entry.tsx +4 -1
- package/src/document.tsx +17 -5
- package/src/index.ts +12 -2
- package/src/lang.ts +28 -0
- package/src/link.tsx +37 -9
- package/src/locale.ts +5 -0
- package/src/metadata.tsx +207 -11
- package/src/modules.ts +19 -3
- package/src/mounted.tsx +3 -3
- package/src/navigation-guard.ts +136 -0
- package/src/offline.ts +97 -0
- package/src/payload.ts +78 -8
- package/src/render-document.tsx +10 -1
- package/src/root.tsx +22 -10
- package/src/route-tree.tsx +18 -7
- package/src/router.tsx +765 -104
- package/src/schema.ts +11 -0
- package/src/service-worker.ts +632 -0
- package/src/testing-vitest.ts +1 -1
- package/src/testing.tsx +68 -15
- package/template/Dockerfile +1 -1
- package/template/Dockerfile.pnpm +68 -0
- package/template/Dockerfile.workspace +52 -0
- package/template/Dockerfile.workspace.dockerignore +15 -0
- package/template/README.md +6 -2
- package/template/_AGENTS.md +9 -3
- package/template/app/layout.tsx +0 -1
- package/template/docker-compose.override.yml +15 -3
- package/template/generated/netjes.ts +1 -1
- package/tsconfig.strict-app.json +27 -0
- package/vite/packages.mjs +97 -0
- package/vite/plugin.d.ts +8 -1
- package/vite/plugin.mjs +156 -9
- /package/template/{public/favicon.svg → app/icon.svg} +0 -0
package/dist/testing.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type ActionState } from './actions.tsx';
|
|
|
4
4
|
import type { AntiforgeryToken, Params } from './payload.ts';
|
|
5
5
|
import { type NavigationState } from './router.tsx';
|
|
6
6
|
export { type RenderDocumentOptions, inlineScriptHashes, renderDocument } from './render-document.tsx';
|
|
7
|
+
export type { DocumentHead, HeadIcon } from './payload.ts';
|
|
7
8
|
/** What the fake app of `createTestApp` reports to the components under test. */
|
|
8
9
|
export type TestAppOptions = {
|
|
9
10
|
/** The current URL. Default `/`. */
|
|
@@ -37,6 +38,22 @@ export type TestAppOptions = {
|
|
|
37
38
|
defaultOptions?: DefaultOptions;
|
|
38
39
|
/** What `useNavigation()` returns. Default idle. */
|
|
39
40
|
navigation?: NavigationState;
|
|
41
|
+
/**
|
|
42
|
+
* The `useHistoryState` values of the history entry on screen, by name: what a navigation carried into it
|
|
43
|
+
* (`historyState`), or what an earlier visit left there. Default none.
|
|
44
|
+
*/
|
|
45
|
+
historyState?: Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* What `usePageActionState()` returns after the page action's input failed its checks, as the server sends it with a
|
|
48
|
+
* 422: the errors per field and the submitted values of the fields the action declares (default none). `status` is
|
|
49
|
+
* the failure's status, 422 by default, or 429 for a post the rate limiter refused. It belongs to the page, so `route`
|
|
50
|
+
* names it; without `route`, the page is the URL's path. Default no failure.
|
|
51
|
+
*/
|
|
52
|
+
pageActionState?: {
|
|
53
|
+
errors: Record<string, string[]>;
|
|
54
|
+
values?: Record<string, string | string[]>;
|
|
55
|
+
status?: number;
|
|
56
|
+
};
|
|
40
57
|
/** The token `<Form method="post">` adds. Default a test token; `false` for none. */
|
|
41
58
|
antiforgery?: AntiforgeryToken | false;
|
|
42
59
|
queryClient?: QueryClient;
|
|
@@ -66,6 +83,7 @@ export type TestActionAnswer = ActionState<unknown> & {
|
|
|
66
83
|
export type TestNavigation = {
|
|
67
84
|
type: 'push' | 'replace';
|
|
68
85
|
href: string;
|
|
86
|
+
historyState?: Readonly<Record<string, unknown>>;
|
|
69
87
|
} | {
|
|
70
88
|
type: 'refresh' | 'back' | 'forward';
|
|
71
89
|
} | {
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,cAAc,EAAE,WAAW,EAAgC,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAE,KAAK,SAAS,EAAsC,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAqB,KAAK,WAAW,EAAmB,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,cAAc,EAAE,WAAW,EAAgC,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAE,KAAK,SAAS,EAAsC,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAqB,KAAK,WAAW,EAAmB,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,EAAE,MA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ACnH,MAAM,MAAM,OAAO,GAAG;IACpB,2CAA2C;IAC3C,OAAO,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,KAAK,SAAS,CAAC;IACvD,6DAA6D;IAC7D,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAiCF,wKAAwK;AACxK,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAqInE"}
|
package/dist/testing.js
CHANGED
|
@@ -7,6 +7,7 @@ import { useLayoutEffect, useMemo, useState } from 'react';
|
|
|
7
7
|
import { setActionClient } from './actions.js';
|
|
8
8
|
import { PublicConfigProvider } from './public-config.js';
|
|
9
9
|
import { dehydratedStateOf, mergeOptions } from './query.js';
|
|
10
|
+
import { NavigationGuards } from './navigation-guard.js';
|
|
10
11
|
import { RouterContexts } from './router.js';
|
|
11
12
|
export { inlineScriptHashes, renderDocument } from './render-document.js';
|
|
12
13
|
/**
|
|
@@ -72,17 +73,44 @@ export function createTestApp(options = {}) {
|
|
|
72
73
|
};
|
|
73
74
|
function Wrapper({ children }) {
|
|
74
75
|
const [url, setUrl] = useState(initialUrl);
|
|
76
|
+
// The useHistoryState values of the entry on screen, and their lineage: as the router's, a navigation to another page
|
|
77
|
+
// starts a new one, and a setter of the lineage before sets nothing.
|
|
78
|
+
const [historyEntry, setHistoryEntry] = useState(() => ({
|
|
79
|
+
lineage: 0,
|
|
80
|
+
values: options.historyState ?? {},
|
|
81
|
+
}));
|
|
82
|
+
// Stable, as the router's, so a setter is a new function only in a new lineage.
|
|
83
|
+
const [historyWriters] = useState(() => ({
|
|
84
|
+
set: (lineage, name, compute) => setHistoryEntry((entry) => (entry.lineage === lineage ? { lineage, values: { ...entry.values, [name]: compute(entry.values) } } : entry)),
|
|
85
|
+
onRestore: () => () => { },
|
|
86
|
+
}));
|
|
87
|
+
const history = useMemo(() => ({ ...historyEntry, ...historyWriters }), [historyEntry, historyWriters]);
|
|
88
|
+
const [guards] = useState(() => new NavigationGuards());
|
|
75
89
|
const router = useMemo(() => {
|
|
76
|
-
const go = (type, href) => {
|
|
77
|
-
navigations.push({ type, href });
|
|
90
|
+
const go = (type, href, historyState) => {
|
|
91
|
+
navigations.push(historyState ? { type, href, historyState } : { type, href });
|
|
78
92
|
const next = new URL(href, window.location.href);
|
|
93
|
+
// As the router does: a page that stays keeps its values, another starts over; what the navigation carries goes on top.
|
|
94
|
+
const stays = next.pathname === window.location.pathname;
|
|
95
|
+
setHistoryEntry(({ lineage, values }) => stays ? { lineage, values: { ...values, ...historyState } } : { lineage: lineage + 1, values: { ...historyState } });
|
|
79
96
|
window.history.replaceState(null, '', next.href);
|
|
80
97
|
setUrl(next);
|
|
81
98
|
return Promise.resolve();
|
|
82
99
|
};
|
|
100
|
+
// As the router does: a guard that holds is asked first, except about a fragment of the page on screen or
|
|
101
|
+
// another site, and the navigation is recorded once the guards let it go on. One that goes at once, as no guard
|
|
102
|
+
// holds, takes the place of an attempt still waiting for its answer.
|
|
103
|
+
const guarded = (type, href, historyState) => {
|
|
104
|
+
const next = new URL(href, window.location.href);
|
|
105
|
+
const here = new URL(window.location.href);
|
|
106
|
+
const keepsPage = next.hash !== '' && next.pathname === here.pathname && next.search === here.search;
|
|
107
|
+
if (next.origin !== here.origin || keepsPage)
|
|
108
|
+
return go(type, href, historyState);
|
|
109
|
+
return guards.attempt(next.pathname + next.search + next.hash, type, () => go(type, href, historyState));
|
|
110
|
+
};
|
|
83
111
|
return {
|
|
84
|
-
push: (href) =>
|
|
85
|
-
replace: (href) =>
|
|
112
|
+
push: (href, navigateOptions) => guarded('push', href, navigateOptions?.historyState),
|
|
113
|
+
replace: (href, navigateOptions) => guarded('replace', href, navigateOptions?.historyState),
|
|
86
114
|
prefetch: () => { },
|
|
87
115
|
refresh: () => {
|
|
88
116
|
navigations.push({ type: 'refresh' });
|
|
@@ -97,24 +125,37 @@ export function createTestApp(options = {}) {
|
|
|
97
125
|
onActionResponse: () => () => { },
|
|
98
126
|
onCookiesChanged: () => () => { },
|
|
99
127
|
};
|
|
100
|
-
}, []);
|
|
101
|
-
const payload = useMemo(() =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
}, [guards]);
|
|
129
|
+
const payload = useMemo(() => {
|
|
130
|
+
const route = options.route ?? (options.pageActionState ? url.pathname : null);
|
|
131
|
+
return {
|
|
132
|
+
kind: 'page',
|
|
133
|
+
route,
|
|
134
|
+
page: null,
|
|
135
|
+
segments: [],
|
|
136
|
+
props: {},
|
|
137
|
+
params: options.params ?? {},
|
|
138
|
+
shared: options.shared ?? null,
|
|
139
|
+
status: options.pageActionState ? (options.pageActionState.status ?? 422) : 200,
|
|
140
|
+
url: url.pathname + url.search,
|
|
141
|
+
version: 'test',
|
|
142
|
+
...(antiforgery ? { antiforgery } : {}),
|
|
143
|
+
...(options.draftMode ? { draftMode: true } : {}),
|
|
144
|
+
...(options.locale ? { locale: options.locale } : {}),
|
|
145
|
+
...(options.mounts ? { mounts: options.mounts } : {}),
|
|
146
|
+
...(options.pageActionState && route !== null
|
|
147
|
+
? {
|
|
148
|
+
actionState: {
|
|
149
|
+
action: route,
|
|
150
|
+
status: options.pageActionState.status ?? 422,
|
|
151
|
+
errors: options.pageActionState.errors,
|
|
152
|
+
values: options.pageActionState.values ?? {},
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
: {}),
|
|
156
|
+
};
|
|
157
|
+
}, [url]);
|
|
158
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(PublicConfigProvider, { value: options.publicConfig ?? {}, children: _jsxs(RouterContexts, { router: router, payload: payload, url: url, navigation: options.navigation ?? { state: 'idle' }, history: history, guards: guards, children: [_jsx(RegisterActionClient, { client: actionClient }), children] }) }) }));
|
|
118
159
|
}
|
|
119
160
|
return { Wrapper, navigations, queryClient };
|
|
120
161
|
}
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":";AAAA,mHAAmH;AACnH,6GAA6G;AAC7G,uFAAuF;AACvF,OAAO,EAAuB,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAkB,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAuC,eAAe,EAAE,MAAM,cAAe,CAAC;AAErF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAa,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":";AAAA,mHAAmH;AACnH,6GAA6G;AAC7G,uFAAuF;AACvF,OAAO,EAAuB,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAkB,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAuC,eAAe,EAAE,MAAM,cAAe,CAAC;AAErF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAa,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAuE,cAAc,EAAmB,MAAM,aAAc,CAAC;AAEpI,OAAO,EAA8B,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAuB,CAAC;AAqFvG;;;;;GAKG;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AC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAEV,OAAO,CACL,KAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW,YACtC,KAAC,oBAAoB,IAAC,KAAK,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE,YACrD,MAAC,cAAc,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAC/I,KAAC,oBAAoB,IAAC,MAAM,EAAE,YAAY,GAAI,EAC7C,QAAQ,IACM,GACI,GACH,CACvB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netjes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Build React apps and sites on ASP.NET Core: the Next.js App Router conventions, C# loaders and server actions, streaming SSR and types from C# to the browser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"types": "./dist/testing-setup.d.ts",
|
|
49
49
|
"default": "./dist/testing-setup.js"
|
|
50
50
|
},
|
|
51
|
+
"./testing/vitest": {
|
|
52
|
+
"types": "./dist/testing-vitest.d.ts",
|
|
53
|
+
"default": "./dist/testing-vitest.js"
|
|
54
|
+
},
|
|
51
55
|
"./vitals": {
|
|
52
56
|
"types": "./dist/vitals.d.ts",
|
|
53
57
|
"default": "./dist/vitals.js"
|
|
@@ -56,6 +60,10 @@
|
|
|
56
60
|
"types": "./dist/zod.d.ts",
|
|
57
61
|
"default": "./dist/zod.js"
|
|
58
62
|
},
|
|
63
|
+
"./service-worker": {
|
|
64
|
+
"types": "./dist/service-worker.d.ts",
|
|
65
|
+
"default": "./dist/service-worker.js"
|
|
66
|
+
},
|
|
59
67
|
"./client-entry": {
|
|
60
68
|
"types": "./dist/client-entry.d.ts",
|
|
61
69
|
"default": "./dist/client-entry.js"
|
|
@@ -64,7 +72,8 @@
|
|
|
64
72
|
"types": "./dist/server-entry.d.ts",
|
|
65
73
|
"default": "./dist/server-entry.js"
|
|
66
74
|
},
|
|
67
|
-
"./sidecar": "./sidecar/server.mjs"
|
|
75
|
+
"./sidecar": "./sidecar/server.mjs",
|
|
76
|
+
"./tsconfig.strict-app.json": "./tsconfig.strict-app.json"
|
|
68
77
|
},
|
|
69
78
|
"bin": {
|
|
70
79
|
"netjes": "./bin/netjes.mjs"
|
|
@@ -78,17 +87,19 @@
|
|
|
78
87
|
"cli",
|
|
79
88
|
"skills",
|
|
80
89
|
"template",
|
|
90
|
+
"tsconfig.strict-app.json",
|
|
81
91
|
"README.md",
|
|
82
92
|
"LICENSE"
|
|
83
93
|
],
|
|
84
94
|
"scripts": {
|
|
85
|
-
"build": "tsc -p tsconfig.build.json",
|
|
95
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.service-worker.json",
|
|
86
96
|
"prepack": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && npm run build",
|
|
87
97
|
"test": "vitest run",
|
|
88
|
-
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.strict-
|
|
98
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.strict-src.json && tsc -p tsconfig.service-worker.json --noEmit && tsc -p test/fixtures/service-worker/tsconfig.json"
|
|
89
99
|
},
|
|
90
100
|
"dependencies": {
|
|
91
|
-
"@vitejs/plugin-react": "^6.1.2"
|
|
101
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
102
|
+
"yaml": "^2.9.1"
|
|
92
103
|
},
|
|
93
104
|
"peerDependencies": {
|
|
94
105
|
"@tailwindcss/vite": "^4.0.0",
|
package/sidecar/server.mjs
CHANGED
|
@@ -8,16 +8,23 @@
|
|
|
8
8
|
// pings a process that has answered no render for a while; any answer will do, and a process that sends nothing back
|
|
9
9
|
// within the render timeout (at least 5 s) is killed and restarted. Every request must carry the X-Netjes-Token the
|
|
10
10
|
// parent passed in NETJES_TOKEN. Renders are aborted when the caller disconnects, when the shell is not ready after
|
|
11
|
-
// NETJES_RENDER_TIMEOUT_MS, or when the whole stream takes longer than NETJES_STREAM_TIMEOUT_MS.
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
11
|
+
// NETJES_RENDER_TIMEOUT_MS, or when the whole stream takes longer than NETJES_STREAM_TIMEOUT_MS. Reads lines on stdin:
|
|
12
|
+
// `stopping`, which the parent sends in development once the app begins to stop, makes the Vite dev server let go of
|
|
13
|
+
// its port and end its connections, while renders go on. Exits when stdin closes (or on SIGTERM or SIGINT), after
|
|
14
|
+
// letting go of the Vite port first.
|
|
15
|
+
// Startup: prints NETJES_READY {"port","viteOrigin"} on stdout once it listens. A Vite port that is taken is tried
|
|
16
|
+
// again for up to VITE_PORT_WAIT_MS, after a line on stdout that says so. When the Vite dev server does not start, it
|
|
17
|
+
// prints NETJES_FAILED and exits with code 1: {"reason":"vite-port-in-use","port"} when its port is still taken, and
|
|
15
18
|
// {"reason":"vite-failed","message","code"} for anything else, such as an error in vite.config or a package it imports
|
|
16
19
|
// that is not installed (message in plain text; code is the error's when it has one, such as ERR_MODULE_NOT_FOUND, or
|
|
17
20
|
// MODULE_NOT_FOUND from a CommonJS config).
|
|
21
|
+
import { readFileSync } from 'node:fs';
|
|
18
22
|
import http from 'node:http';
|
|
23
|
+
import { createRequire } from 'node:module';
|
|
19
24
|
import path from 'node:path';
|
|
25
|
+
import { createInterface } from 'node:readline';
|
|
20
26
|
import { pipeline } from 'node:stream/promises';
|
|
27
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
21
28
|
import { pathToFileURL } from 'node:url';
|
|
22
29
|
|
|
23
30
|
const mode = process.env.NETJES_MODE === 'development' ? 'development' : 'production';
|
|
@@ -30,6 +37,12 @@ delete process.env.NETJES_TOKEN;
|
|
|
30
37
|
const renderTimeoutMs = Number(process.env.NETJES_RENDER_TIMEOUT_MS ?? 15_000);
|
|
31
38
|
const streamTimeoutMs = Number(process.env.NETJES_STREAM_TIMEOUT_MS ?? 60_000);
|
|
32
39
|
const vitePort = Number(process.env.NETJES_VITE_PORT ?? 5173);
|
|
40
|
+
// How long the Vite dev server waits for its port when something has it, and how often it tries the port meanwhile.
|
|
41
|
+
// dotnet watch starts an app again while the process of the one before may still have the port: that process lets go
|
|
42
|
+
// of it as soon as it hears that its app is stopping, or when its stdin closes (below). A port that something else
|
|
43
|
+
// keeps is reported once the wait is over.
|
|
44
|
+
const VITE_PORT_WAIT_MS = 5_000;
|
|
45
|
+
const VITE_PORT_RETRY_MS = 100;
|
|
33
46
|
const MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
34
47
|
const CSS_FILE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)$/;
|
|
35
48
|
// Terminal escape sequences (ECMA-48): CSI, as ESC [ or its one-character form (colours, as in Vite's code frames, which
|
|
@@ -52,6 +65,11 @@ let render;
|
|
|
52
65
|
let renderToStream;
|
|
53
66
|
/** @type {import('vite').ViteDevServer | undefined} */
|
|
54
67
|
let vite;
|
|
68
|
+
/**
|
|
69
|
+
* The connections to the Vite dev server (a browser's requests, its HMR socket), which releaseVitePort ends.
|
|
70
|
+
* @type {Set<import('node:net').Socket>}
|
|
71
|
+
*/
|
|
72
|
+
const viteSockets = new Set();
|
|
55
73
|
|
|
56
74
|
/**
|
|
57
75
|
* Says why the Vite dev server did not start, for .NET to report in a line of its own (Node's report of an uncaught
|
|
@@ -72,13 +90,34 @@ const viteFailed = (error) =>
|
|
|
72
90
|
code: error instanceof Error && 'code' in error && typeof error.code === 'string' ? error.code : undefined,
|
|
73
91
|
});
|
|
74
92
|
|
|
93
|
+
/** @returns {Promise<typeof import('vite')>} */
|
|
94
|
+
async function loadVite() {
|
|
95
|
+
let entry;
|
|
96
|
+
try {
|
|
97
|
+
entry = createRequire(path.join(root, 'package.json')).resolve('vite');
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND')) throw error;
|
|
100
|
+
return import('vite');
|
|
101
|
+
}
|
|
102
|
+
// These helpers ship with the dev sidecar. The production build copies only this script.
|
|
103
|
+
const { findPackage } = await import('../cli/packages.mjs');
|
|
104
|
+
const { satisfies } = await import('../cli/info.mjs');
|
|
105
|
+
const manifest = findPackage(root, 'vite');
|
|
106
|
+
const version = manifest ? JSON.parse(readFileSync(manifest, 'utf8')).version : undefined;
|
|
107
|
+
const range = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).peerDependencies.vite;
|
|
108
|
+
if (!satisfies(version, range, { strict: true })) {
|
|
109
|
+
console.warn(`netjes: the app's Vite (${version ?? 'unknown version'}) is outside the supported range (${range}); using the Vite resolved from netjes.`);
|
|
110
|
+
return import('vite');
|
|
111
|
+
}
|
|
112
|
+
return import(pathToFileURL(entry).href);
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
if (mode === 'development') {
|
|
76
116
|
const origin = process.env.NETJES_VITE_ORIGIN ?? `http://localhost:${vitePort}`;
|
|
77
117
|
/** @type {import('vite').ViteDevServer} */
|
|
78
118
|
let dev;
|
|
79
119
|
try {
|
|
80
|
-
|
|
81
|
-
const { createServer } = await import('vite');
|
|
120
|
+
const { createServer } = await loadVite();
|
|
82
121
|
dev = await createServer({
|
|
83
122
|
root,
|
|
84
123
|
appType: 'custom',
|
|
@@ -90,14 +129,43 @@ if (mode === 'development') {
|
|
|
90
129
|
dev = await viteFailed(error);
|
|
91
130
|
}
|
|
92
131
|
vite = dev;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
132
|
+
dev.httpServer?.on('connection', (/** @type {import('node:net').Socket} */ socket) => {
|
|
133
|
+
viteSockets.add(socket);
|
|
134
|
+
socket.once('close', () => viteSockets.delete(socket));
|
|
135
|
+
});
|
|
136
|
+
/**
|
|
137
|
+
* Starts the dev server listening. Vite adds a listener for the server's 'listening' event each time; a start that
|
|
138
|
+
* fails leaves it behind, and it goes, so that trying the port again and again (below) does not pile them up.
|
|
139
|
+
*/
|
|
140
|
+
const listen = async () => {
|
|
141
|
+
const httpServer = dev.httpServer;
|
|
142
|
+
const before = new Set(httpServer?.listeners('listening'));
|
|
143
|
+
try {
|
|
144
|
+
await dev.listen();
|
|
145
|
+
} catch (error) {
|
|
146
|
+
for (const listener of httpServer?.listeners('listening') ?? []) {
|
|
147
|
+
if (!before.has(listener)) httpServer?.off('listening', /** @type {(...args: unknown[]) => void} */ (listener));
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const waitUntil = performance.now() + VITE_PORT_WAIT_MS;
|
|
153
|
+
for (let waiting = false; ; ) {
|
|
154
|
+
try {
|
|
155
|
+
await listen();
|
|
156
|
+
break;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (!(error instanceof Error && error.message === `Port ${vitePort} is already in use`)) await viteFailed(error);
|
|
159
|
+
// Still taken: most often another app's Vite dev server. .NET names the port and how to move it.
|
|
160
|
+
if (performance.now() >= waitUntil) await failStartup({ reason: 'vite-port-in-use', port: vitePort });
|
|
161
|
+
if (!waiting) {
|
|
162
|
+
waiting = true;
|
|
163
|
+
console.log(
|
|
164
|
+
`netjes: port ${vitePort} is in use; waiting up to ${VITE_PORT_WAIT_MS / 1000}s for it, in case the app that ran before is still stopping`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
await sleep(VITE_PORT_RETRY_MS);
|
|
99
168
|
}
|
|
100
|
-
await viteFailed(error);
|
|
101
169
|
}
|
|
102
170
|
const netjes = /** @type {NetjesDevApi | undefined} */ (dev.config.plugins.find((plugin) => plugin.name === 'netjes')?.api);
|
|
103
171
|
/** @param {unknown} error @returns {error is Error & { file: string }} */
|
|
@@ -403,7 +471,22 @@ server.listen(0, '127.0.0.1', () => {
|
|
|
403
471
|
process.stdout.write(`NETJES_READY ${JSON.stringify({ port, viteOrigin })}\n`);
|
|
404
472
|
});
|
|
405
473
|
|
|
474
|
+
/**
|
|
475
|
+
* Stops the Vite dev server listening, so that its port is free for the app that replaces this one, and ends the
|
|
476
|
+
* connections browsers have to it: their Vite client then waits for a dev server to answer on the port again, and
|
|
477
|
+
* reloads the page. Renders go on, since they load modules through Vite and not over its port. Once is enough.
|
|
478
|
+
*/
|
|
479
|
+
function releaseVitePort() {
|
|
480
|
+
const httpServer = vite?.httpServer;
|
|
481
|
+
if (!httpServer?.listening) return;
|
|
482
|
+
// The port is free once close returns; the connections are not waited for.
|
|
483
|
+
httpServer.close();
|
|
484
|
+
for (const socket of viteSockets) socket.destroy();
|
|
485
|
+
}
|
|
486
|
+
|
|
406
487
|
async function shutdown() {
|
|
488
|
+
// The port first: Vite's own close comes to its HTTP server last.
|
|
489
|
+
releaseVitePort();
|
|
407
490
|
server.close();
|
|
408
491
|
await vite?.close();
|
|
409
492
|
process.exit(0);
|
|
@@ -412,8 +495,14 @@ async function shutdown() {
|
|
|
412
495
|
// A promise rejected by page code without a handler would otherwise kill every render in flight.
|
|
413
496
|
process.on('unhandledRejection', (reason) => console.error('netjes: unhandled promise rejection', reason));
|
|
414
497
|
|
|
415
|
-
//
|
|
416
|
-
|
|
498
|
+
// What the parent says, a line at a time. `stopping`: the app has begun to stop, and may take a while to finish the
|
|
499
|
+
// requests it has (in development; NodeSidecar.cs). The app that replaces it needs the Vite dev server's port now.
|
|
500
|
+
createInterface({ input: process.stdin }).on('line', (line) => {
|
|
501
|
+
if (line.trim() === 'stopping') releaseVitePort();
|
|
502
|
+
});
|
|
503
|
+
// The parent keeps our stdin open for as long as it lives; EOF means it is gone. Ahead of the handlers Vite adds for
|
|
504
|
+
// the same events, which close the dev server with its port last.
|
|
505
|
+
process.stdin.prependListener('end', shutdown);
|
|
417
506
|
process.stdin.resume();
|
|
418
|
-
process.
|
|
507
|
+
process.prependListener('SIGTERM', shutdown);
|
|
419
508
|
process.on('SIGINT', shutdown);
|
package/skills/netjes/SKILL.md
CHANGED
|
@@ -70,13 +70,15 @@ export default definePage(pages['/blog/[slug]'], function Post({ title, body })
|
|
|
70
70
|
|
|
71
71
|
- Decisions live in C#: data access, validation, authorization (`.RequireAuthorization()`, `Page.Forbidden()`), redirects, caching. React renders what it is sent.
|
|
72
72
|
- Loaders and actions return Netjes results (`Page.Props(...)`, `Page.NotFound()`, `ServerAction.Ok(...)`), so their types reach `generated/netjes.ts`. Use records for everything that crosses to the browser.
|
|
73
|
-
- zod at every boundary: `definePage`/`defineLayout` with the generated schemas, `useSearchParams(schema)` and `useParams(schema)` (schemas at module level), `api[...].response.parse(...)` for fetched JSON (from `useHref(endpointUrl(...))`, never a hand-built URL), `usePublicConfig(schema)`, `Href.parse(...)` or `isHref(...)` for URLs from a CMS. A link C# sends to one of the app's pages is a `Href` in the record (`new Href("/about")`), generated as the `Href` schema, so it reaches `<Link href>` checked; a link to an endpoint or a file stays a `string`. No `any`, no casts of server data.
|
|
73
|
+
- zod at every boundary: `definePage`/`defineLayout` with the generated schemas, `useSearchParams(schema)` and `useParams(schema)` (schemas at module level), `useHistoryState(name, initial, schema)` for what a history entry holds, `api[...].response.parse(...)` for fetched JSON (from `useHref(endpointUrl(...))`, never a hand-built URL), `usePublicConfig(schema)`, `Href.parse(...)` or `isHref(...)` for URLs from a CMS. A link C# sends to one of the app's pages is a `Href` in the record (`new Href("/about")`), generated as the `Href` schema, so it reaches `<Link href>` checked; a link to an endpoint or a file stays a `string`. No `any`, no casts of server data.
|
|
74
74
|
- Server state goes through TanStack Query, seeded from the loader with `.WithQuery(key, data)`; no `useEffect` fetching.
|
|
75
|
-
- Internal links use `<Link>` and `route()`; forms use `<Form>` with `useAction`, and must work without JavaScript.
|
|
75
|
+
- Internal links use `<Link>` and `route()`; forms use `<Form>` with `useAction`, and must work without JavaScript. A form whose changes would be lost by leaving holds navigations with `useNavigationGuard` and asks ([references/routing.md](references/routing.md)).
|
|
76
76
|
- Give each page a title of its own (`metadata`, or `PageMetadata` from C#), and keep the "Skip to content" link the first thing in the root layout, `app/layout.tsx`, that takes the focus, also when the root layout is kept bare and the site's chrome is in a group layout such as `app/(site)/layout.tsx`: after a client navigation the router announces the page by its title and starts the focus over at the top ([references/routing.md](references/routing.md)).
|
|
77
|
+
- Icons, `apple-icon.png` and `manifest.webmanifest` go at the root of `app/` and are served and linked for you; the viewport is `export const viewport`, never a `<meta>` of your own ([routing](references/routing.md#metadata)).
|
|
78
|
+
- Pages that must open offline opt in with `.AvailableOffline()` and a worker built on `netjes/service-worker` ([offline pages](references/caching-and-streaming.md#offline-pages)); with pnpm, `netjes new` writes a pnpm Dockerfile and runs on the host ([deployment](references/deployment.md#docker)).
|
|
77
79
|
- Never edit `generated/netjes.ts`; regenerate it and commit it with the change.
|
|
78
80
|
- Anything in `Netjes:PublicConfig` or shared props is sent to the browser. So is the route of each endpoint with an `endpointUrl` key, one mapped only in Development included, once any component calls `endpointUrl`: keep secrets out of routes, and authorize on the endpoint.
|
|
79
|
-
- Caching, streaming and static export have sharp edges: read [references/caching-and-streaming.md](references/caching-and-streaming.md) before using `.CachePage`, `Page.Defer` or `netjes
|
|
81
|
+
- Caching, streaming and static export have sharp edges: read [references/caching-and-streaming.md](references/caching-and-streaming.md) before using `.CachePage`, `Page.Defer`, `netjes export` or `netjes/service-worker` (offline pages).
|
|
80
82
|
- Shipping: [references/deployment.md](references/deployment.md).
|
|
81
83
|
|
|
82
84
|
## Commands
|
|
@@ -82,6 +82,27 @@ function ActivityFeed({ activity }: { activity: PromiseLike<ActivityItem[]> }) {
|
|
|
82
82
|
- A boundary that is ready when the shell goes out is written in place, so it shows without JavaScript too.
|
|
83
83
|
- A value that fails rejects, so `use()` throws to the nearest `error.tsx`: with error details off its message is a stand-in marked `withheld`, and a cancelled task fails with "The value was cancelled".
|
|
84
84
|
|
|
85
|
+
## Offline pages
|
|
86
|
+
|
|
87
|
+
A few opted-in pages can open without a network through the app's own service worker, built on `offlinePages()` from `netjes/service-worker`:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
// sw.ts, type-checked with "lib": ["ES2023", "WebWorker"]
|
|
91
|
+
import { offlinePages } from 'netjes/service-worker';
|
|
92
|
+
declare const self: ServiceWorkerGlobalScope;
|
|
93
|
+
const offline = offlinePages({ fallback: '/offline', basePath: '' });
|
|
94
|
+
self.addEventListener('install', (e) => offline.install(e));
|
|
95
|
+
self.addEventListener('activate', (e) => offline.activate(e));
|
|
96
|
+
self.addEventListener('fetch', (e) => { if (offline.handle(e)) return; /* the app's own rules */ });
|
|
97
|
+
self.addEventListener('message', (e) => offline.message(e));
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- The worker stores only what the server marked with `X-Netjes-Offline: 1` (the page endpoints opted in with `.AvailableOffline()`), in one cache per visitor and registration, and serves a stored copy when the network fails or is slower than `networkTimeout` (3000 ms). A page load it has no copy of gets the `fallback` page, a payload a network error, so the router keeps the page on screen.
|
|
101
|
+
- Stored pages belong to the visitor in `X-Netjes-Offline-Scope`: a page for another visitor (sign-in, sign-out, another account, `unknown`) deletes every stored page, and an answer whose request began before that is never stored. A marked page whose visitor had no cache as its request began, and has one once its answer arrives (the first opted-in page after a change, or one on its way when another page opened the cache), is fetched once more in the background, never a third time. That second request is an ordinary one: stored only when its visitor's cache existed, alone, as it began and was not deleted on its way; after a sign-out its answer is the next visitor's. A visitor whose cache existed as the original request began (even one a clear deleted on the way) gets no second request. After `await clearOffline()` resolves, nothing whose request began before it was called is stored, that second request included. On a shared device, sign out, then `await clearOffline()`: it deletes the page caches by name and needs no worker. Without Web Locks in the browser it stores and serves no pages (the fallback page is still stored).
|
|
102
|
+
- The fallback page is fetched without cookies and survives every change of visitor: it must show nothing personal.
|
|
103
|
+
- It takes only same-origin `GET`s below the base path: page loads, payload requests and files under `/assets/` named as Vite names its built files (it goes by the name alone, and fetches them without cookies). JSON endpoints, event streams and other origins are left to the app's own rules.
|
|
104
|
+
- `keep(urls)` (the client's `netjes:keep` message, answered on the message's port once done) stores pages ahead; `clear()` deletes every stored page.
|
|
105
|
+
|
|
85
106
|
## Static export
|
|
86
107
|
|
|
87
108
|
`npx netjes export [dir]` builds, runs the app once in Production and writes every page as static HTML (default `out/`). `dir` must be inside the app: `netjes export` refuses any other folder before it builds. Dynamic pages need `.StaticParams(...)` (`.StaticParams<PostStore>(s => s.All.Select(p => new { slug = p.Slug }))`, arrays for catch-all parameters); pages that need a server take `.ExcludeFromExport()`. The export fails before writing anything for a dynamic page without static params, a page with a page action, or a page that requires authorization. Exported pages navigate with full page loads and carry no antiforgery token.
|
|
@@ -98,4 +119,4 @@ Leave `/_netjes/` out of `disallow`: `<Image>` serves every image through `/_net
|
|
|
98
119
|
|
|
99
120
|
## More
|
|
100
121
|
|
|
101
|
-
[Caching](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/caching.md), [
|
|
122
|
+
[Rendering and streaming](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/rendering-and-streaming.md), [Caching](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/caching.md), [Offline pages](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/offline.md) and [Static export](https://github.com/DennisVerhoeven/netjes/blob/main/docs/guides/static-export.md) in the guides.
|
|
@@ -18,7 +18,7 @@ app.MapPageLoader("/projects/[id]", async (string id, ClaimsPrincipal user, AppD
|
|
|
18
18
|
|
|
19
19
|
- It binds like a minimal API: route values by name, services, `ClaimsPrincipal`, `HttpContext`, `CancellationToken`, `[FromQuery]`.
|
|
20
20
|
- It reads no request body, so a complex type that is not a registered service needs `[AsParameters]` or a static `BindAsync`. A loader or action whose parameters minimal APIs cannot bind stops the app at startup, saying which and why. So does a loader parameter that reads the body (`[FromBody]`, `[FromForm]`, `IFormFile`): posted data belongs in a page action or a server action. A page loader stops the app too for a type that adds accepts metadata (`IAcceptsMetadata`) for itself, and must not get `.Accepts<T>()`: routing would match the page only for requests with that Content-Type, and navigations would get the not-found page. Repeated query values bind to an array (`int[] ids`); `List<int>` and `IEnumerable<int>` stop the app at startup, the latter because minimal APIs would bind it from services.
|
|
21
|
-
- `Page.Props(record)` names the props type for `pages['/projects/[id]']`. `Page.NotFound()`, `Page.Forbidden()`, `Page.Unauthorized()` render the nearest boundary file; `Page.Redirect(url)` and `Page.LocalRedirect(returnUrl)` (for URLs from the request) redirect, and the client router follows them
|
|
21
|
+
- `Page.Props(record)` names the props type for `pages['/projects/[id]']`. `Page.NotFound()`, `Page.Forbidden()`, `Page.Unauthorized()` render the nearest boundary file; `Page.Redirect(url)` and `Page.LocalRedirect(returnUrl)` (for URLs from the request) redirect, and the client router follows them; one to a URL no page answers (a signed file URL, an endpoint) the browser loads once, as a document, so a page action's download form needs no `reloadDocument`. `.WithStatus(422)` changes the status.
|
|
22
22
|
- A link to one of the app's pages is a `Href` in the props record (`public sealed record NavLink(Href Href, string Label)`, `new Href($"/projects/{Uri.EscapeDataString(id)}")`, with each value encoded), root-relative, in the page file's spelling (the props parse compares literal segments with their case, so `/About` fails for `app/about/page.tsx`) and without the base path. It is generated as the `Href` schema, so the props parse checks it against the pages and the component passes it to `<Link href>` as it is. `new Href(url)` throws `ArgumentException` unless the URL starts with `/` (and not `//` or `/\`), `?`, `#`, `http:`, `https:`, `mailto:` or `tel:`, and also for a control character anywhere in it or a space at either end; `Href.TryCreate` returns false instead. C# checks only that shape: a root-relative `Href` that no page serves fails the whole props parse and the page shows its error boundary (a 500 from the server only when no Suspense boundary, such as a `loading.tsx`, is above the component that parses; otherwise the server sends that boundary's fallback with the loader's status), so a link to an endpoint or a file, such as `/llms.txt`, stays a `string`, rendered with `useHref`, and so does a link from a CMS, checked with `isHref` where it is rendered. No query or route value binds to an `Href`: a `returnUrl` stays a `string` for `Page.LocalRedirect`, and a `[FromForm]` input takes a `string`, since form binding reads no `Href` from the field of its name. `LinkGenerator`'s `HttpContext` overloads add the base path, so pass `pathBase: PathString.Empty`.
|
|
23
23
|
- It returns a `RouteHandlerBuilder`: `.RequireAuthorization()`, `.CachePage(...)` and filters apply.
|
|
24
24
|
- A page's loader runs before its layouts' loaders, so a page under a layout that checks access checks it too.
|
|
@@ -74,11 +74,12 @@ const nameError = state?.ok === false ? state.errors.name?.[0] : undefined;
|
|
|
74
74
|
- Every action needs `app.UseAntiforgery()` (after authentication) and checks the origin; `<Form>` and `serverActions` send the token. `MapAction` bodies are limited to 1 MB (`ActionBodySizeLimit`); an upload action sets `[RequestSizeLimit(bytes)]`. Page actions keep the server's limit.
|
|
75
75
|
- Name actions `feature.verb`. Names are compared ignoring case, and a second `MapAction` of a name, the app's or a page package's, stops the app at startup. Every action answers at `/_netjes/actions/{name}`, so `MapAction` in a `MapGroup` with a prefix throws; map it on the app, or on `MapGroup("")` for shared conventions. Check authorization inside the action, or with `.RequireAuthorization()`, as for any endpoint.
|
|
76
76
|
- `app.MapPageAction("/guestbook", ...)` is the other kind: a POST to the page's own URL from `<Form method="post">`, fields typed in `forms['/guestbook']`. Its input's DataAnnotations and `IValidatableObject` are checked as for `MapAction`: on a failure the delegate does not run, the page renders again from its loader (422), and `const failed = usePageActionState()` gives `failed.errors` and `failed.values` (null otherwise). Checks that need data stay in the delegate: return `Page.Props(...)` with your own errors and the typed values (`.WithStatus(422)`), or `Page.Redirect(...)` after a change.
|
|
77
|
-
-
|
|
77
|
+
- A rate limit goes on the action (`.RequireRateLimiting("sign-in")`, `app.UseRateLimiter()` after `app.UseNetjes()`), with `limiter.OnRejected = (context, _) => Page.TooManyRequests(context, "Too many attempts.")`: a refused page action renders its page again with 429, and `usePageActionState()` gives `failed.status === 429`, the message in `failed.errors['']` and the declared fields' values (never a password); a server action's form without JavaScript gets the same through `useAction`, and a script's call throws `ServerActionError` (429, the message). Without it, a refused post gets the error page.
|
|
78
|
+
- An action or post that sets or deletes a cookie (signing in or out) makes the client router forget the pages it keeps for back and forward, reload the page on screen and clear the query cache, in every tab of the app in that browser. Nothing to do in the action; a proxy must pass `X-Netjes-Cookies` through. A cookie that changes nothing another page shows, such as a cart's, goes in `options.NoReloadCookies = ["cart"]` (or a prefix ending in `*` for a name per store: `".app.cart.*"`; a `*` elsewhere stops the app at startup): an action that writes only those reloads nothing, so return what changed or call `.Refresh()`. A cookie authentication scheme's cookie always reloads, listed, covered by a prefix or not.
|
|
78
79
|
|
|
79
80
|
## Page packages
|
|
80
81
|
|
|
81
|
-
A mounted page package's loaders, layout loaders, actions and endpoints are mapped by the package's extension, through its mount, and typed in the package's own generated file, not in the app's. The app's `generated/netjes.ts` routes the package's pages (`route('/help/contact')`) and holds only what the app maps itself; run `npx netjes generate` after updating a package. The app's `MapPageLoader`, `MapPageAction` and `MapLayoutLoader` refuse a package's page or layout, naming the mount. A page the app replaces with `.Override` renders with the package's loader, so it reads its props from the package's file: `definePage(pages['/contact'], ...)` with `pages` from `'@acme/help-center/generated'`. The app's own pages under the prefix, and their loaders, are the app's as before. Schemas both sides read by key, such as an export a package adds with `AddTypeScriptExport`, are in both files.
|
|
82
|
+
A mounted page package's loaders, layout loaders, actions and endpoints are mapped by the package's extension, through its mount, and typed in the package's own generated file, not in the app's. The app's `generated/netjes.ts` routes the package's pages (`route('/help/contact')`) and holds only what the app maps itself; run `npx netjes generate` after updating a package. The app's `MapPageLoader`, `MapPageAction` and `MapLayoutLoader` refuse a package's page or layout, naming the mount. A page the app replaces with `.Override` renders with the package's loader, so it reads its props from the package's file: `definePage(pages['/contact'], ...)` with `pages` from `'@acme/help-center/generated'`. The app's own pages under the prefix, and their loaders, are the app's as before. Schemas both sides read by key, such as an export a package adds with `AddTypeScriptExport`, are in both files; with `appOnly: true` an export is in the app's alone.
|
|
82
83
|
|
|
83
84
|
## JSON endpoints and TanStack Query
|
|
84
85
|
|
|
@@ -97,7 +98,7 @@ const url = useHref(endpointUrl('GET /api/projects/{slug}/stats', { slug }));
|
|
|
97
98
|
const stats = useQuery({ queryKey: ['projects', slug, 'stats'], queryFn: () => fetchStats(url) });
|
|
98
99
|
```
|
|
99
100
|
|
|
100
|
-
Typed results (`TypedResults`, `Results<...>`) give the endpoint its `api` schemas, keyed by method and route template. `endpointUrl(key, params, search)` builds the URL of the app's endpoints that are not pages, JSON or not (a JSON endpoint has a key per method except `HEAD`, any other endpoint one for `GET`, if it answers `GET`), by the same key: the route values and the query values its handler binds are typed from C#, an enum as its C# names and values, and `search` adds others. It has no base path: `useHref` adds it, for a `fetch` or an `<a href>`. Its result is a `string`, which the type of `<Link href>` does not accept, as an endpoint is not a page: link it with `<a href={useHref(endpointUrl(...))}>`. Seed the same query key from the loader with `.WithQuery(key, data)` and the query renders on the server with no fetch; keep the key in one place on each side. Seeded data is fresh for the default `staleTime` (one minute).
|
|
101
|
+
Typed results (`TypedResults`, `Results<...>`) give the endpoint its `api` schemas, keyed by method and route template. `endpointUrl(key, params, search)` builds the URL of the app's endpoints that are not pages, JSON or not (a JSON endpoint has a key per method except `HEAD`, any other endpoint one for `GET`, if it answers `GET`, and one for `POST`, if it accepts a posted form, so `<Form method="post" action={endpointUrl('POST /users/{id}/export', { id })}>` posts to a download), by the same key: the route values and the query values its handler binds are typed from C#, an enum as its C# names and values, and `search` adds others. It has no base path: `useHref` adds it, for a `fetch` or an `<a href>`. Its result is a `string`, which the type of `<Link href>` does not accept, as an endpoint is not a page: link it with `<a href={useHref(endpointUrl(...))}>`. Seed the same query key from the loader with `.WithQuery(key, data)` and the query renders on the server with no fetch; keep the key in one place on each side. Seeded data is fresh for the default `staleTime` (one minute).
|
|
101
102
|
|
|
102
103
|
`MapGet` answers `GET` only: a `HEAD` to its URL goes to whatever else matches it, often the not-found page. For an endpoint that crawlers, link checkers or monitors ask with `HEAD`, map `app.MapMethods(pattern, [HttpMethods.Get, HttpMethods.Head], handler)`; its `api` key stays `GET` and the route. Pages, `/sitemap.xml`, `/robots.txt`, `/_netjes/image` and the locale redirect answer `HEAD` already.
|
|
103
104
|
|
|
@@ -18,14 +18,14 @@ For these startup failures the app logs one critical entry, saying what is wrong
|
|
|
18
18
|
|
|
19
19
|
## Docker
|
|
20
20
|
|
|
21
|
-
`netjes new` writes a `Dockerfile` and Compose files:
|
|
21
|
+
`netjes new` writes a `Dockerfile` and, for an npm app, Compose files (a standalone pnpm app gets them with `--compose`, and a pnpm workspace app never does: it builds with `docker build -f <app>/Dockerfile .` from the workspace root):
|
|
22
22
|
|
|
23
23
|
- `docker compose up`: development, with `dotnet watch` and Vite HMR, ports bound to localhost.
|
|
24
24
|
- `docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d`: the production image, a non-root user on a read-only filesystem, with a health check on `/healthz` and Data Protection keys in a named volume.
|
|
25
|
-
- Both publish the app on host port 8080; `APP_PORT` (in the shell or a `.env` file) moves it. Vite
|
|
25
|
+
- Both publish the app on host port 8080; `APP_PORT` (in the shell or a `.env` file) moves it. Development also publishes Vite on 5173, which `VITE_PORT` moves (the same port inside and out, with `Netjes__ViteDevPort` set to it).
|
|
26
26
|
- The production image runs `tini -s -- dotnet MyApp.dll`: tini is PID 1, passes `docker stop`'s SIGTERM on, and exits with the app's code, so a crash ends the container (134) and `restart: always` acts. When .NET itself is a container's PID 1, its abort does not end it. On arm64 it spins at 100% CPU and never exits; after a crash later than startup the rest of the app keeps serving and `/healthz` still passes. On x86-64 under emulation it has been seen to exit after a few seconds, with 139 instead of 134. An image of the app's own, or one from an older template, needs an init too: the template's `tini` stage, its `COPY` and the `ENTRYPOINT`, or the host's (`docker run --init`, Compose `init: true`, ECS `initProcessEnabled`).
|
|
27
27
|
|
|
28
|
-
The image restores Netjes from NuGet and npm, so the app must reference the packages, as an app made with `npx netjes new` does (from a Netjes checkout, pass `--packages`).
|
|
28
|
+
The image restores Netjes from NuGet and npm, so the app must reference the packages, as an app made with `npx netjes new` does (from a Netjes checkout, pass `--packages`). For pnpm (`netjes new` picks it when pnpm launches it or a pnpm workspace is above the app, or with `--package-manager pnpm`), run `pnpm dev` on the host and build with `docker build .` from the app folder; an app in a pnpm workspace builds from the workspace root with `docker build -f <app>/Dockerfile .`. Behind a proxy, streamed responses and event streams already carry `X-Accel-Buffering: no`; an app's own value wins.
|
|
29
29
|
|
|
30
30
|
## Production settings
|
|
31
31
|
|