@stopnetic/js 0.0.5-pilot → 0.0.6-pilot

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 CHANGED
@@ -6,18 +6,21 @@ frontend build. No React/Vue/Angular dependency or version upgrade is required.
6
6
  The hosting server must run Node.js 22 or newer. This is an MIT-licensed pilot SDK;
7
7
  hosted production/provider validation is still required before paid rollout.
8
8
 
9
- Version **0.0.5-pilot is prepared locally; it is not published yet**. The guide
10
- offers two explicit rendering paths: preserve SSR or retain a static/CSR app.
11
- Server document navigation is the default; leave startup/layout unchanged with
12
- no global checking screen. Optional SPA demos for all six frontends explain
13
- their asynchronous checks and use empty pending content. Unchanged
14
- 0.0.2/0.0.3/0.0.4 guides migrate safely; custom edits require merging.
9
+ Version **0.0.6-pilot is prepared locally; it is not published yet**. It adds
10
+ framework-specific SSR instructions and a dashboard SSR selector for Angular,
11
+ React Router, custom React SSR, Nuxt, custom Vue SSR, SvelteKit, Astro, SolidStart
12
+ and custom Node servers. Examples identify the actual server entry, prerender
13
+ settings, deployed Node runtime and context/body preservation. Next.js uses its
14
+ dedicated adapter; other languages/Edge are explicitly outside this Node SDK.
15
+ Unchanged 0.0.2/0.0.3/0.0.4/0.0.5 guides migrate safely; custom edits require merging.
16
+ SSR and static rendering remain separate choices, with document navigation
17
+ default and no global checking screen. Optional browser demos remain available.
15
18
  Angular, React, Vue, Svelte, Solid and plain JavaScript share the browser/server
16
19
  contracts; no React dependency is required. See the
17
20
  [complete generated guide](dist/client-guide.md) for SSR, static builds, frameworks,
18
21
  client navigation, API protection and runtime restrictions.
19
22
 
20
- The currently published **0.0.4-pilot** includes full frontend examples and the
23
+ The currently published **0.0.5-pilot** clarifies rendering/navigation and includes full frontend examples and the
21
24
  framework-independent server/browser setup, complete Node application wrapper
22
25
  and older-guide migration. Version 0.0.2 added the reusable browser/server setup for Netlify, Vercel
23
26
  and Node/Express, a browser access check and optional React boundary. It also
@@ -30,6 +33,36 @@ npm install @stopnetic/js@pilot
30
33
 
31
34
  ## Framework implementation examples
32
35
 
36
+ SSR apps use the **SSR framework** selector, not the optional browser-demo
37
+ selector. [Framework SSR instructions](dist/client-guide.md#ssr-framework-instructions)
38
+ and `examples/ssr` contain matching server code:
39
+
40
+ | SSR app | Server connection |
41
+ | --- | --- |
42
+ | Angular | AngularAppEngine Fetch entry or Express before AngularNodeAppEngine |
43
+ | React Router | Existing Express entry; single-fetch `.data` aliases use page policy |
44
+ | Custom React / Vue | Guard before the existing Node renderer; keep hydration |
45
+ | Nuxt 3/4 (Nitro 2/H3 1) | Root Node server middleware before rendering/APIs |
46
+ | SvelteKit | `handle` before `resolve(event)`; canonical page check for data requests |
47
+ | Astro | `onRequest` before `next()` with an existing Node adapter |
48
+ | SolidStart 1 / 2 | Version-specific request middleware before continuation |
49
+ | Custom Node / plain JavaScript | Root Express middleware or complete Fetch wrapper |
50
+ | Next.js | Dedicated `@stopnetic/next` guide |
51
+
52
+ Merge existing files/context, preserve public routes and keep protected output
53
+ out of prerender/static/CDN caches. These manual snippets are not automatic
54
+ framework installers. Node compatibility does not validate a live provider.
55
+ Only dashboard rules decide verification; Angular-specific flags are not instructions
56
+ for other frameworks. React/Vue libraries without a server use the static option.
57
+
58
+ To test server continuation contracts after `npm run build`, run
59
+ `node tests/prepare-ssr-guide-tests.mjs`, then `node tests/ssr-guide-check.mjs`.
60
+ Dependencies remain in ignored test-results. Native H3 1/2 and Express exercise
61
+ signed access, control isolation, data aliases and unread POST bodies. Astro,
62
+ SvelteKit and SolidStart factory imports use contract shims, not full framework
63
+ builds. Angular's separate fixture compiles/renders real SSR. Live routing,
64
+ prerender/cache behavior and complete framework/provider builds still need validation.
65
+
33
66
  The guide and `examples/frontend` contain complete, locally tested OPTIONAL
34
67
  browser-only SPA examples. The default document-navigation integration needs
35
68
  the server guard and normal links, not these full-layout browser gates. Keep SSR
@@ -71,7 +104,7 @@ npm run build
71
104
  npm pack
72
105
  ```
73
106
 
74
- Install the resulting `stopnetic-js-0.0.5-pilot.tgz` into the website project using
107
+ Install the resulting `stopnetic-js-0.0.6-pilot.tgz` into the website project using
75
108
  `npm install <absolute-path-to-tarball>`. The installed package has no Next.js or
76
109
  other runtime dependency. The build packages the same signed decision implementation
77
110
  as the Next.js adapter. Keep `@stopnetic/next` for its Next.js 16 guided installer.
@@ -2,9 +2,11 @@
2
2
 
3
3
  Angular, React, Vue, Svelte, Solid and plain JavaScript use the same server guard
4
4
  and browser access check. React is optional. Install `@stopnetic/js` in the
5
- website project; choose a hosting platform, not a frontend framework.
5
+ website project. The CLI chooses hosting files; choose your actual SSR framework
6
+ in the instructions below to see where its server guard belongs.
6
7
 
7
- Jump to your implementation: [React Router](#react-router),
8
+ Start with [SSR framework instructions](#ssr-framework-instructions) if the app
9
+ renders on the server. Optional browser-only demos: [React Router](#react-router),
8
10
  [Angular Router](#angular-router), [Vue Router](#vue-router),
9
11
  [Svelte](#svelte-navigation), [Solid Router](#solid-router),
10
12
  [plain JavaScript](#plain-javascript-navigation). Each section includes the
@@ -148,11 +150,57 @@ the shared guard before its `resolve`, `next` or renderer. A Fetch wrapper is
148
150
  for a complete handler returning a Response, not every framework middleware
149
151
  signature. Node/Express can mount the generated helper around any renderer.
150
152
 
153
+ <!-- BEGIN SSR EXAMPLES -->
154
+
155
+ ### SSR framework instructions
156
+
157
+ Choose the actual SSR framework, not just the browser UI library. Angular
158
+ instructions apply ONLY to Angular. Each section below identifies the server
159
+ file, integration steps, prerender constraints and runtime. The same sections
160
+ appear in the dashboard SSR framework selector. Merge examples into existing
161
+ entries; do not replace SSR, hydration, context or application features.
162
+
163
+ Use your selected framework hook OR the shared Node wrapper above. Do not
164
+ stack both or mount the generated Express helper as an additional guard.
165
+
166
+ | Your app | Choose |
167
+ | --- | --- |
168
+ | Angular with SSR | Angular SSR |
169
+ | React Router framework/server mode | React Router SSR |
170
+ | React plus your own Node renderer | React custom SSR |
171
+ | Nuxt | Nuxt (Vue SSR) |
172
+ | Vue plus your own Node renderer | Vue custom SSR |
173
+ | SvelteKit | SvelteKit SSR |
174
+ | Astro on-demand rendering | Astro SSR |
175
+ | SolidStart | SolidStart SSR; match the installed major version |
176
+ | Other Node renderer / plain JavaScript server | Other Node SSR |
177
+ | Next.js | Dedicated @stopnetic/next guide; do not install the JS control files |
178
+ | React/Vue/Svelte/Solid UI without an SSR server | Option B: static/browser app |
179
+ | PHP, Python, Ruby, C#, Java or Edge/Deno | No native adapter in this Node npm SDK; a separate runtime adapter/gateway is needed |
180
+
181
+ All snippets require SDK 0.0.3-pilot or newer and six SERVER settings. They
182
+ are manual integration examples, not automatic installers for each framework.
183
+ Validate the actual deployed adapter, versions, internal data endpoints and
184
+ cache/static aliases. Hook-contract checks do not prove provider deployment.
185
+
151
186
  ### Angular SSR on Node
152
187
 
153
- For a Fetch-style Angular SSR entry in `src/server.ts`:
188
+ **Where:** src/server.ts (Fetch entry), or your existing Express server.ts before AngularNodeAppEngine.handle.
189
+
190
+ 1. Keep server.ts, main.server.ts, server providers, host configuration and hydration. Merge the guard into the existing request entry; preserve extra framework context.
191
+ 2. Use the Fetch example only for an AngularAppEngine Request/Response entry. An Express entry instead mounts the Node helper before express.static and AngularNodeAppEngine.handle.
192
+ 3. Protected paths use RenderMode.Server. The wildcard below is an example, not a replacement for existing public/hybrid route configuration.
193
+
194
+ **Prerendering and caches:** Do not publish protected RenderMode.Prerender output to a public CDN. Retain public rendering modes only where they cannot bypass future protection. Any path the dashboard may protect must reach the server guard before HTML.
195
+
196
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
197
+
198
+ **Netlify Angular only:** Netlify’s automatic Angular SSR uses Edge Functions. The current Node SDK has no drop-in integration for that combination. Keep SSR; obtain a supported Node deployment or gateway decision. A static index.html function is not an Angular SSR adapter.
199
+
200
+ #### src/server.ts
154
201
 
155
202
  ```ts
203
+ // Merge into your existing Node SSR entry; retain host settings and context.
156
204
  import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
157
205
  import { createStopneticAppHandler } from '@stopnetic/js/server';
158
206
 
@@ -166,36 +214,364 @@ async function handle(request: Request): Promise<Response> {
166
214
  export const reqHandler = createRequestHandler(handle);
167
215
  ```
168
216
 
169
- Keep existing Angular host configuration and request context if your entry
170
- uses them. For an Express-based Angular entry, mount `installStopnetic(app)`
171
- before `express.static` and `AngularNodeAppEngine.handle` instead.
172
-
173
- Protected routes in `src/app/app.routes.server.ts` must use request-time
174
- rendering rather than `RenderMode.Prerender`:
217
+ #### src/app/app.routes.server.ts
175
218
 
176
219
  ```ts
177
220
  import { RenderMode, ServerRoute } from '@angular/ssr';
178
221
  export const serverRoutes: ServerRoute[] = [
179
- // All routes are rendered on incoming requests in this example.
222
+ // Demo only: merge with existing hybrid modes rather than replacing them.
180
223
  { path: '**', renderMode: RenderMode.Server },
181
224
  ];
182
225
  ```
183
226
 
184
- This is an all-request-time demonstration, not an instruction to replace an
185
- existing hybrid route configuration. Preserve public rendering modes where
186
- appropriate. Any path the dashboard may protect must reach the guard before
187
- HTML is served; publicly cached/prerendered HTML bypassing it cannot be protected
188
- by adding a dashboard rule alone. Plan server coverage for those paths first.
227
+ Framework references: [Angular SSR](https://angular.dev/guide/ssr), [Netlify Angular runtime](https://docs.netlify.com/build/frameworks/framework-setup-guides/angular/).
228
+
229
+ ### React Router framework mode on Node
230
+
231
+ **Where:** Existing Express entry before @react-router/express createRequestHandler.
232
+
233
+ 1. React Router framework mode supplies the SSR server. Keep its server build, loaders/actions, getLoadContext and hydration; BrowserRouter alone is not an SSR backend.
234
+ 2. Copy the helper, then import and call it at the application root before parsers/assets and the existing createRequestHandler. Do not place it after the renderer or mount it at a stripped URL prefix.
235
+ 3. The helper checks React Router 7 .data requests against their page path, including /_root.data. The actual router still receives its original URL and unread body. This example uses the default / basename; custom basenames and other router versions need alias mapping review.
236
+
237
+ **Prerendering and caches:** Keep ssr enabled in react-router.config.ts. Exclude protected paths from prerender output and CDN caches. Direct .data requests must not expose private loaders merely because the document path is guarded. Independently authorize resource routes, actions and server functions.
238
+
239
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
240
+
241
+ #### stopnetic-react-router.mjs
242
+
243
+ ```js
244
+ // Call installStopneticReactRouter(app) before parsers, assets and the existing
245
+ // @react-router/express createRequestHandler. Keep that handler/context intact.
246
+ import { createStopneticServer } from '@stopnetic/js/server';
247
+
248
+ export function installStopneticReactRouter(app) {
249
+ let server;
250
+ app.use((req, res, next) => {
251
+ server ??= createStopneticServer();
252
+ return server.access(req, res, () => {
253
+ // React Router 7 single-fetch data URLs must use the page's policy.
254
+ // The renderer still receives the original request and unread body.
255
+ const url = new URL(req.originalUrl || req.url, 'https://example.invalid');
256
+ let checked = req;
257
+ if (url.pathname.endsWith('.data')) {
258
+ url.pathname = url.pathname === '/_root.data' ? '/' : url.pathname.slice(0, -5);
259
+ checked = Object.create(req);
260
+ checked.originalUrl = url.pathname + url.search;
261
+ }
262
+ return server.guard(checked, res, next);
263
+ });
264
+ });
265
+ }
266
+ ```
267
+
268
+ #### Existing Express entry (merge fragment)
269
+
270
+ ```js
271
+ // In your EXISTING Express entry, before parsers, static files and rendering:
272
+ import { installStopneticReactRouter } from './stopnetic-react-router.mjs';
273
+ installStopneticReactRouter(app);
274
+ // Keep the existing renderer, application routes and server startup below.
275
+ ```
276
+
277
+ Framework references: [React Router server adapters](https://reactrouter.com/api/other-api/adapter), [React Router prerendering](https://reactrouter.com/how-to/pre-rendering).
278
+
279
+ ### React with an existing custom SSR server
280
+
281
+ **Where:** Existing Node/Express server before React rendering and any private data handler.
282
+
283
+ 1. React is a UI library; this option assumes you already have a Node SSR server. Keep renderToPipeableStream/renderToReadableStream, request context and hydrateRoot.
284
+ 2. Copy the helper and call it before the existing assets/API/renderer middleware. For a Fetch-style server use the custom Node Fetch wrapper instead.
285
+ 3. A Vite React SPA without a server uses Option B: static/browser app. Next.js and React Router SSR have their own selector entries. Do not add a second renderer or replace the app with the browser demo.
286
+
287
+ **Prerendering and caches:** Do not statically publish protected HTML or embed private data in public bundles. Keep guarded rendering at request time, retaining public prerendering only with correct server/CDN coverage.
288
+
289
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
290
+
291
+ #### stopnetic-react-ssr.mjs
292
+
293
+ ```js
294
+ // Existing custom React SSR server: call before assets, APIs and React rendering.
295
+ // Keep renderToPipeableStream/renderToReadableStream and hydration unchanged.
296
+ import { createStopneticServer } from '@stopnetic/js/server';
297
+ export function installStopneticReactSSR(app) {
298
+ let server;
299
+ app.use((req, res, next) => {
300
+ server ??= createStopneticServer();
301
+ return server.access(req, res, () => server.guard(req, res, next));
302
+ });
303
+ }
304
+ ```
305
+
306
+ #### Existing Express entry (merge fragment)
307
+
308
+ ```js
309
+ // In your EXISTING Express entry, before parsers, static files and rendering:
310
+ import { installStopneticReactSSR } from './stopnetic-react-ssr.mjs';
311
+ installStopneticReactSSR(app);
312
+ // Keep the existing renderer, application routes and server startup below.
313
+ ```
314
+
315
+ Framework references: [React Node SSR](https://react.dev/reference/react-dom/server/renderToPipeableStream).
316
+
317
+ ### Nuxt 3/4 with Nitro 2 and H3 1 on Node
318
+
319
+ **Where:** server/middleware/00-stopnetic.mjs; runs before Nitro renders pages and serves API handlers.
320
+
321
+ 1. Keep Nuxt SSR, its app, pages, hydration and existing Node Nitro preset. Check the installed Nitro/H3 versions; this example uses H3 1 fromNodeMiddleware, not the H3 2 API.
322
+ 2. Add this server middleware before other body readers and handlers. app/middleware and defineNuxtRouteMiddleware are navigation UI hooks and cannot replace this server guard.
323
+ 3. Keep the private environment settings in the deployed Node process. Do not use runtimeConfig.public. Test the built server and separate provider functions, not only Nuxt dev.
324
+
325
+ **Prerendering and caches:** Do not use nuxt generate or prerender/SWR/ISR/cached route rules for protected paths. Protected _payload.json files must not be generated into public output. Keep public route rules only where they cannot expose protected content through CDN/cache aliases.
326
+
327
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
328
+
329
+ #### server/middleware/00-stopnetic.mjs
330
+
331
+ ```js
332
+ // server/middleware/00-stopnetic.mjs. Nuxt 3/4, Nitro 2, H3 1, NODE only.
333
+ // Use server middleware, not app/middleware or defineNuxtRouteMiddleware.
334
+ import { fromNodeMiddleware } from 'h3';
335
+ import { createStopneticServer } from '@stopnetic/js/server';
336
+
337
+ let server;
338
+ export default fromNodeMiddleware((req, res, next) => {
339
+ server ??= createStopneticServer();
340
+ return server.access(req, res, () => server.guard(req, res, next));
341
+ });
342
+ ```
343
+
344
+ Framework references: [Nuxt server middleware](https://nuxt.com/docs/4.x/directory-structure/server), [H3 1 Node middleware adapter](https://v1.h3.dev/examples/from-expressjs-to-h3).
345
+
346
+ ### Vue with an existing custom SSR server
347
+
348
+ **Where:** Existing Node/Express server before Vue rendering and private APIs.
349
+
350
+ 1. Vue alone is a UI library. Keep the existing createSSRApp/renderToString server, request context and client hydration.
351
+ 2. Copy and mount the helper before the existing parsers/assets/API/renderer middleware. For a Request/Response server use the custom Node Fetch wrapper.
352
+ 3. A Vue SPA uses Option B. A Nuxt app uses the Nuxt entry; do not replace either with a newly invented Express renderer.
353
+
354
+ **Prerendering and caches:** Protected HTML and private serialized state must be produced only after the server check. Avoid publicly cached/prerendered output for protected paths.
355
+
356
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
357
+
358
+ #### stopnetic-vue-ssr.mjs
359
+
360
+ ```js
361
+ // Existing custom Vue SSR server: call before assets, APIs and Vue rendering.
362
+ // Keep createSSRApp/renderToString and client hydration unchanged.
363
+ import { createStopneticServer } from '@stopnetic/js/server';
364
+ export function installStopneticVueSSR(app) {
365
+ let server;
366
+ app.use((req, res, next) => {
367
+ server ??= createStopneticServer();
368
+ return server.access(req, res, () => server.guard(req, res, next));
369
+ });
370
+ }
371
+ ```
372
+
373
+ #### Existing Express entry (merge fragment)
374
+
375
+ ```js
376
+ // In your EXISTING Express entry, before parsers, static files and rendering:
377
+ import { installStopneticVueSSR } from './stopnetic-vue-ssr.mjs';
378
+ installStopneticVueSSR(app);
379
+ // Keep the existing renderer, application routes and server startup below.
380
+ ```
381
+
382
+ Framework references: [Vue SSR](https://vuejs.org/guide/scaling-up/ssr.html).
383
+
384
+ ### SvelteKit server hooks on Node
385
+
386
+ **Where:** src/hooks.server.js, before resolve(event) and any existing application hooks.
387
+
388
+ 1. Keep the existing Node adapter, SSR pages, loads/actions and hydration. Merge this handle into existing hooks; put Stopnetic first and retain other hooks in its continuation.
389
+ 2. The guard receives the original request and per-request continuation. Data requests are checked against event.url, the canonical page path, then resolve receives the original event and body.
390
+ 3. Merge prerender=false into each protected +page.server.js or a covering server layout. building skips runtime enforcement only during build; no protected path may be prerendered. Test with the full adapter server.
391
+
392
+ **Prerendering and caches:** Keep SSR enabled. The runtime handle hook does not protect files already served statically. Exclude protected routes from prerender output, including __data.json. Do not rely on a page rule alone for separately exposed endpoints or remote functions.
393
+
394
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
395
+
396
+ #### src/hooks.server.js
397
+
398
+ ```js
399
+ import { building } from '$app/environment';
400
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
401
+
402
+ let guarded;
403
+ // When merging existing hooks, run this first and put them in the continuation.
404
+ export async function handle({ event, resolve }) {
405
+ // Build-time public prerendering only. Protected routes must have prerender=false.
406
+ if (building) return resolve(event);
407
+ guarded ??= createStopneticAppHandler((_request, run) => run());
408
+ // SvelteKit exposes the canonical page URL on data requests. Check that page
409
+ // rather than allowing an unmatched /members/__data.json alias through.
410
+ const checked = event.isDataRequest
411
+ ? new Request(event.url, { method: event.request.method, headers: event.request.headers })
412
+ : event.request;
413
+ return guarded(checked, () => resolve(event));
414
+ }
415
+ ```
416
+
417
+ #### src/routes/members/+page.server.js (merge example)
418
+
419
+ ```js
420
+ // Merge into the PROTECTED route's +page.server.js, retaining loads/actions.
421
+ export const prerender = false;
422
+ export const ssr = true;
423
+ ```
424
+
425
+ Framework references: [SvelteKit server hooks](https://svelte.dev/docs/kit/hooks), [SvelteKit page options](https://svelte.dev/docs/kit/page-options).
426
+
427
+ ### Astro request middleware on Node
428
+
429
+ **Where:** src/middleware.js, before next() renders a page or executes an endpoint.
430
+
431
+ 1. Keep the existing compatible Node adapter and Astro renderer. If middleware exists, merge/sequence this guard first, preserving locals and the existing continuation.
432
+ 2. Use context.request and next(), not a browser startup gate. The isPrerendered branch is build-only public rendering; protected pages must never enter it.
433
+ 3. Set prerender=false on protected .astro pages/endpoints. Keep their existing content. For @astrojs/node middleware mode, an outer Express guard before static files is also available; do not install both patterns unnecessarily.
434
+
435
+ **Prerendering and caches:** Protected pages need on-demand rendering with a Node adapter. Public prerendered pages can remain public, but files bypassing request middleware cannot acquire protection through a dashboard rule alone.
436
+
437
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
438
+
439
+ #### src/middleware.js
440
+
441
+ ```js
442
+ // src/middleware.js. Keep the existing Node deployment adapter.
443
+ import { defineMiddleware } from 'astro:middleware';
444
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
445
+
446
+ let guarded;
447
+ export const onRequest = defineMiddleware(async (context, next) => {
448
+ // Public prerender builds only; protected pages must export prerender=false.
449
+ if (context.isPrerendered) return next();
450
+ guarded ??= createStopneticAppHandler((_request, run) => run());
451
+ return guarded(context.request, () => next());
452
+ });
453
+ ```
454
+
455
+ #### src/pages/members.astro (frontmatter flag)
456
+
457
+ ```astro
458
+ ---
459
+ // Merge this flag into a protected page, preserving its existing content.
460
+ export const prerender = false;
461
+ ---
462
+ ```
463
+
464
+ Framework references: [Astro middleware](https://docs.astro.build/en/guides/middleware/), [Astro Node adapter](https://docs.astro.build/en/guides/integrations-guide/node/).
465
+
466
+ ### SolidStart request middleware on Node
467
+
468
+ **Where:** src/middleware.js, registered in the existing SolidStart config before rendering and API execution.
469
+
470
+ 1. Choose the snippet matching your installed major version. SolidStart 2 uses createMiddleware([...]) and H3 event.req/event.res; SolidStart 1 uses onRequest and event.request/event.response.
471
+ 2. For v2 register solidStart({ middleware: "./src/middleware.js" }) in existing vite.config.ts. For v1 register middleware in existing defineConfig in app.config.ts. Keep all other settings and the SSR entry-server.tsx.
472
+ 3. A per-request allowed marker distinguishes an authorized continuation from a verification 204. The framework continues only when the marker is set; no renderer runs on challenge/block/outage. Server functions still require their own permissions and policy checks for their actual endpoint paths.
473
+
474
+ **Prerendering and caches:** Keep SSR enabled and protected routes out of prerender/static/ISR output. Use the existing Node server plugin/preset; do not assume a middleware export changes an Edge deployment into Node.
475
+
476
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
477
+
478
+ #### src/middleware.js — SolidStart 2
479
+
480
+ ```js
481
+ // SolidStart 2: register this module using solidStart({ middleware: ... }).
482
+ import { createMiddleware } from '@solidjs/start/middleware';
483
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
484
+
485
+ let check;
486
+ export default createMiddleware([
487
+ async (event, next) => {
488
+ check ??= createStopneticAppHandler((_request, state) => {
489
+ state.allowed = true;
490
+ return new Response(null, { status: 204 });
491
+ });
492
+ // Per-request state: a verification 204 must NEVER be mistaken for permission.
493
+ const state = { allowed: false };
494
+ const response = await check(event.req, state);
495
+ if (!state.allowed) return response;
496
+ event.res.headers.set('cache-control', 'private, no-store');
497
+ const result = await next(); // Preserve H3/SolidStart context and raw results.
498
+ if (!(result instanceof Response)) return result;
499
+ const headers = new Headers(result.headers);
500
+ headers.set('cache-control', 'private, no-store');
501
+ return new Response(result.body, {
502
+ status: result.status, statusText: result.statusText, headers,
503
+ });
504
+ },
505
+ ]);
506
+ ```
507
+
508
+ #### src/middleware.js — SolidStart 1 alternative
509
+
510
+ ```js
511
+ // SolidStart 1: register using defineConfig({ middleware: './src/middleware.js' }).
512
+ // Keep the existing entry-server.tsx renderer. This is NOT SolidStart 2 config.
513
+ import { createMiddleware } from '@solidjs/start/middleware';
514
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
515
+
516
+ let check;
517
+ export default createMiddleware({
518
+ onRequest: async event => {
519
+ check ??= createStopneticAppHandler((_request, state) => {
520
+ state.allowed = true;
521
+ return new Response(null, { status: 204 });
522
+ });
523
+ const state = { allowed: false };
524
+ const response = await check(event.request, state);
525
+ if (!state.allowed) return response;
526
+ event.response.headers.set('cache-control', 'private, no-store');
527
+ // undefined continues to SolidStart; preserve its rendering and API handling.
528
+ },
529
+ });
530
+ ```
531
+
532
+ Framework references: [SolidStart 2 middleware](https://docs.solidjs.com/solid-start/v2/reference/server/create-middleware), [SolidStart 1 middleware](https://docs.solidjs.com/solid-start/v1/reference/server/create-middleware).
533
+
534
+ ### Custom Node SSR or plain JavaScript server
535
+
536
+ **Where:** Existing root request entry, before static HTML, API data or rendering.
537
+
538
+ 1. Use the Express helper OR the Fetch wrapper according to the existing server signature. Do not replace the renderer or introduce a second server.
539
+ 2. Call installStopneticSSR(app) first for Express. For Fetch, export the protected version of the existing handler using protectSSR(renderApplication); all context arguments are retained.
540
+ 3. Keep the canonical Host and private environment in the Node service. Only expose the guarded entry. Independently guard separately deployed API functions.
541
+
542
+ **Prerendering and caches:** Static HTML/cache aliases must not bypass the guard. Preserve existing public routes and apply protection only through dashboard policies.
543
+
544
+ **Hosting runtime:** Node.js 22+ only. Keep the existing Node hosting adapter; check the deployed runtime, not just the hosting brand. Edge/Deno deployments need a separate supported adapter or a gateway decision. Do not convert SSR to static rendering automatically.
545
+
546
+ #### stopnetic-ssr.mjs
547
+
548
+ ```js
549
+ // Call before parsers, static files, APIs and your existing Node SSR renderer.
550
+ import { createStopneticServer } from '@stopnetic/js/server';
551
+ export function installStopneticSSR(app) {
552
+ let server;
553
+ app.use((req, res, next) => {
554
+ server ??= createStopneticServer();
555
+ return server.access(req, res, () => server.guard(req, res, next));
556
+ });
557
+ }
558
+ ```
559
+
560
+ #### stopnetic-fetch-ssr.mjs
561
+
562
+ ```js
563
+ // Wrap your existing Node Request -> Response renderer; retain all context.
564
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
565
+ export function protectSSR(renderApplication) {
566
+ let guarded;
567
+ return (request, ...context) => {
568
+ guarded ??= createStopneticAppHandler(renderApplication);
569
+ return guarded(request, ...context);
570
+ };
571
+ }
572
+ ```
189
573
 
190
- Netlify's automatic Angular SSR adapter currently uses Edge Functions. This
191
- combination does not have a drop-in integration with the current Node SDK.
192
- Do not import the SDK into that Edge entry or assume a Node function intercepts
193
- the Edge renderer. If SSR must stay, keep the SSR files and explain that a
194
- supported Node SSR deployment or a Node gateway that cannot be bypassed is
195
- needed. A custom Node SSR adapter requires separate deployment/routing work;
196
- the static page-function example is not that adapter. Stop and obtain a rendering
197
- or deployment decision if the current runtime is incompatible. Do not delete
198
- `server.ts`, `main.server.ts`, SSR providers or hydration as a workaround.
574
+ <!-- END SSR EXAMPLES -->
199
575
 
200
576
  ### Static apps on Netlify / Vercel
201
577
 
@@ -932,7 +1308,7 @@ server endpoints.
932
1308
  ## Updating an existing generated guide
933
1309
 
934
1310
  After installing the new SDK, rerun `stopnetic-js init --platform <same-platform>`
935
- (preview with `--dry-run`). An unchanged 0.0.2/0.0.3/0.0.4 generated guide is upgraded
1311
+ (preview with `--dry-run`). An unchanged 0.0.2/0.0.3/0.0.4/0.0.5 generated guide is upgraded
936
1312
  with its setup manifest. Your key, cookie secret and server files are preserved.
937
1313
  Customized guides or handlers require manual merging; switching platforms also
938
1314
  requires review. This command does not publish, deploy or contact Stopnetic.
package/dist/setup.js CHANGED
@@ -39,6 +39,7 @@ const legacyGuideDigests = new Set([
39
39
  'b1f149af44f9ceb08fb80c18cb5d4b521620196f536d8ad422ab94d15d1d125d', // 0.0.2
40
40
  '55e36295b6aa87ad9558cde29786998483095adeae74e149ff5c7fe78507fad7', // published 0.0.3
41
41
  '08f919257d8c85af4e56e842705825832ae2810ed68d5c1dfc8405c8f7be7610', // published 0.0.4
42
+ '45bd696f196c3d1447a978987a787755b239f75e9e6a3697f4efbb210ce75597', // published 0.0.5
42
43
  ]);
43
44
  const clientGuide = readFileSync(new URL('./client-guide.md', import.meta.url), 'utf8');
44
45
 
@@ -0,0 +1,5 @@
1
+ import { RenderMode, ServerRoute } from '@angular/ssr';
2
+ export const serverRoutes: ServerRoute[] = [
3
+ // Demo only: merge with existing hybrid modes rather than replacing them.
4
+ { path: '**', renderMode: RenderMode.Server },
5
+ ];
@@ -0,0 +1,12 @@
1
+ // Merge into your existing Node SSR entry; retain host settings and context.
2
+ import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
3
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
4
+
5
+ const engine = new AngularAppEngine();
6
+ let guarded: ReturnType<typeof createStopneticAppHandler> | undefined;
7
+ async function handle(request: Request): Promise<Response> {
8
+ guarded ??= createStopneticAppHandler(async checked =>
9
+ await engine.handle(checked) ?? new Response(null, { status: 404 }));
10
+ return guarded(request);
11
+ }
12
+ export const reqHandler = createRequestHandler(handle);
@@ -0,0 +1,11 @@
1
+ // src/middleware.js. Keep the existing Node deployment adapter.
2
+ import { defineMiddleware } from 'astro:middleware';
3
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
4
+
5
+ let guarded;
6
+ export const onRequest = defineMiddleware(async (context, next) => {
7
+ // Public prerender builds only; protected pages must export prerender=false.
8
+ if (context.isPrerendered) return next();
9
+ guarded ??= createStopneticAppHandler((_request, run) => run());
10
+ return guarded(context.request, () => next());
11
+ });
@@ -0,0 +1,4 @@
1
+ ---
2
+ // Merge this flag into a protected page, preserving its existing content.
3
+ export const prerender = false;
4
+ ---
@@ -0,0 +1,9 @@
1
+ // Wrap your existing Node Request -> Response renderer; retain all context.
2
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
3
+ export function protectSSR(renderApplication) {
4
+ let guarded;
5
+ return (request, ...context) => {
6
+ guarded ??= createStopneticAppHandler(renderApplication);
7
+ return guarded(request, ...context);
8
+ };
9
+ }
@@ -0,0 +1,9 @@
1
+ // Call before parsers, static files, APIs and your existing Node SSR renderer.
2
+ import { createStopneticServer } from '@stopnetic/js/server';
3
+ export function installStopneticSSR(app) {
4
+ let server;
5
+ app.use((req, res, next) => {
6
+ server ??= createStopneticServer();
7
+ return server.access(req, res, () => server.guard(req, res, next));
8
+ });
9
+ }
@@ -0,0 +1,10 @@
1
+ // server/middleware/00-stopnetic.mjs. Nuxt 3/4, Nitro 2, H3 1, NODE only.
2
+ // Use server middleware, not app/middleware or defineNuxtRouteMiddleware.
3
+ import { fromNodeMiddleware } from 'h3';
4
+ import { createStopneticServer } from '@stopnetic/js/server';
5
+
6
+ let server;
7
+ export default fromNodeMiddleware((req, res, next) => {
8
+ server ??= createStopneticServer();
9
+ return server.access(req, res, () => server.guard(req, res, next));
10
+ });
@@ -0,0 +1,10 @@
1
+ // Existing custom React SSR server: call before assets, APIs and React rendering.
2
+ // Keep renderToPipeableStream/renderToReadableStream and hydration unchanged.
3
+ import { createStopneticServer } from '@stopnetic/js/server';
4
+ export function installStopneticReactSSR(app) {
5
+ let server;
6
+ app.use((req, res, next) => {
7
+ server ??= createStopneticServer();
8
+ return server.access(req, res, () => server.guard(req, res, next));
9
+ });
10
+ }
@@ -0,0 +1,22 @@
1
+ // Call installStopneticReactRouter(app) before parsers, assets and the existing
2
+ // @react-router/express createRequestHandler. Keep that handler/context intact.
3
+ import { createStopneticServer } from '@stopnetic/js/server';
4
+
5
+ export function installStopneticReactRouter(app) {
6
+ let server;
7
+ app.use((req, res, next) => {
8
+ server ??= createStopneticServer();
9
+ return server.access(req, res, () => {
10
+ // React Router 7 single-fetch data URLs must use the page's policy.
11
+ // The renderer still receives the original request and unread body.
12
+ const url = new URL(req.originalUrl || req.url, 'https://example.invalid');
13
+ let checked = req;
14
+ if (url.pathname.endsWith('.data')) {
15
+ url.pathname = url.pathname === '/_root.data' ? '/' : url.pathname.slice(0, -5);
16
+ checked = Object.create(req);
17
+ checked.originalUrl = url.pathname + url.search;
18
+ }
19
+ return server.guard(checked, res, next);
20
+ });
21
+ });
22
+ }
@@ -0,0 +1,19 @@
1
+ // SolidStart 1: register using defineConfig({ middleware: './src/middleware.js' }).
2
+ // Keep the existing entry-server.tsx renderer. This is NOT SolidStart 2 config.
3
+ import { createMiddleware } from '@solidjs/start/middleware';
4
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
5
+
6
+ let check;
7
+ export default createMiddleware({
8
+ onRequest: async event => {
9
+ check ??= createStopneticAppHandler((_request, state) => {
10
+ state.allowed = true;
11
+ return new Response(null, { status: 204 });
12
+ });
13
+ const state = { allowed: false };
14
+ const response = await check(event.request, state);
15
+ if (!state.allowed) return response;
16
+ event.response.headers.set('cache-control', 'private, no-store');
17
+ // undefined continues to SolidStart; preserve its rendering and API handling.
18
+ },
19
+ });
@@ -0,0 +1,25 @@
1
+ // SolidStart 2: register this module using solidStart({ middleware: ... }).
2
+ import { createMiddleware } from '@solidjs/start/middleware';
3
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
4
+
5
+ let check;
6
+ export default createMiddleware([
7
+ async (event, next) => {
8
+ check ??= createStopneticAppHandler((_request, state) => {
9
+ state.allowed = true;
10
+ return new Response(null, { status: 204 });
11
+ });
12
+ // Per-request state: a verification 204 must NEVER be mistaken for permission.
13
+ const state = { allowed: false };
14
+ const response = await check(event.req, state);
15
+ if (!state.allowed) return response;
16
+ event.res.headers.set('cache-control', 'private, no-store');
17
+ const result = await next(); // Preserve H3/SolidStart context and raw results.
18
+ if (!(result instanceof Response)) return result;
19
+ const headers = new Headers(result.headers);
20
+ headers.set('cache-control', 'private, no-store');
21
+ return new Response(result.body, {
22
+ status: result.status, statusText: result.statusText, headers,
23
+ });
24
+ },
25
+ ]);
@@ -0,0 +1,16 @@
1
+ import { building } from '$app/environment';
2
+ import { createStopneticAppHandler } from '@stopnetic/js/server';
3
+
4
+ let guarded;
5
+ // When merging existing hooks, run this first and put them in the continuation.
6
+ export async function handle({ event, resolve }) {
7
+ // Build-time public prerendering only. Protected routes must have prerender=false.
8
+ if (building) return resolve(event);
9
+ guarded ??= createStopneticAppHandler((_request, run) => run());
10
+ // SvelteKit exposes the canonical page URL on data requests. Check that page
11
+ // rather than allowing an unmatched /members/__data.json alias through.
12
+ const checked = event.isDataRequest
13
+ ? new Request(event.url, { method: event.request.method, headers: event.request.headers })
14
+ : event.request;
15
+ return guarded(checked, () => resolve(event));
16
+ }
@@ -0,0 +1,3 @@
1
+ // Merge into the PROTECTED route's +page.server.js, retaining loads/actions.
2
+ export const prerender = false;
3
+ export const ssr = true;
@@ -0,0 +1,10 @@
1
+ // Existing custom Vue SSR server: call before assets, APIs and Vue rendering.
2
+ // Keep createSSRApp/renderToString and client hydration unchanged.
3
+ import { createStopneticServer } from '@stopnetic/js/server';
4
+ export function installStopneticVueSSR(app) {
5
+ let server;
6
+ app.use((req, res, next) => {
7
+ server ??= createStopneticServer();
8
+ return server.access(req, res, () => server.guard(req, res, next));
9
+ });
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stopnetic/js",
3
- "version": "0.0.5-pilot",
3
+ "version": "0.0.6-pilot",
4
4
  "description": "Server-side Stopnetic guard for JavaScript websites, Node.js and Express-compatible servers.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,7 +20,8 @@
20
20
  "files": [
21
21
  "dist",
22
22
  "bin",
23
- "examples/frontend"
23
+ "examples/frontend",
24
+ "examples/ssr"
24
25
  ],
25
26
  "bin": { "stopnetic-js": "./bin/stopnetic-js.js" },
26
27
  "exports": {