docs: publish package usage examples for 0.2.24

This commit is contained in:
2026-07-13 20:58:28 +05:30
parent b07ef5058a
commit 379553bdf7
79 changed files with 1542 additions and 894 deletions
+39 -80
View File
@@ -10,12 +10,12 @@ page wrnexusdevserver {
<header class="topbar">
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
<nav aria-label="Primary"><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.2.23</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.2.24</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
</header>
<div class="mobile-doc-nav"><details><summary>Browse documentation</summary><nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/language">Language</a><a href="/architecture">Architecture</a><a href="/tutorial">Tutorial</a><a href="/guides/project-structure">Guides</a><a href="/examples">Examples</a><a href="/search">Search</a></nav></details></div>
<main class="page package-page">
<aside class="sidebar"><a href="/packages">← All packages</a><span class="category">Runtime</span><h2>@wrnexus/dev-server</h2><p>Development and production servers, HMR, assets, and gateways.</p><span class="status status-beta">Private preview · 0.2.23</span><nav><a href="#access">Access</a><a href="#guide">Guide</a><a href="#api">Complete API</a></nav></aside>
<article id="main" class="documentation"><section class="doc-intro"><span class="eyebrow">Runtime · Preview</span><h1>@wrnexus/dev-server</h1><p>Development and production servers, HMR, assets, and gateways.</p><section id="access" class="access-callout"><h2>Private registry access required</h2><p>This package is not available from the public npm registry. After WorkRoot approves access and supplies private registry instructions, install the release-aligned package:</p><pre><code>bun add @wrnexus/dev-server@0.2.23</code><button type="button" class="copy-button" aria-label="Copy installation command">Copy</button></pre><p><a href="/access">Request preview access</a>. Never put registry tokens in source control.</p></section></section><section id="guide" class="prose"><blockquote>The WRNexusJS HTTP + WebSocket server runtime — request dispatch, SSR document assembly, live-reload (HMR), and the portable production handler.</blockquote>
<aside class="sidebar"><a href="/packages">← All packages</a><span class="category">Runtime</span><h2>@wrnexus/dev-server</h2><p>Development and production servers, HMR, assets, and gateways.</p><span class="status status-beta">Private preview · 0.2.24</span><nav><a href="#access">Access</a><a href="#guide">Guide</a><a href="#api">Complete API</a></nav></aside>
<article id="main" class="documentation"><section class="doc-intro"><span class="eyebrow">Runtime · Preview</span><h1>@wrnexus/dev-server</h1><p>Development and production servers, HMR, assets, and gateways.</p><section id="access" class="access-callout"><h2>Private registry access required</h2><p>This package is not available from the public npm registry. After WorkRoot approves access and supplies private registry instructions, install the release-aligned package:</p><pre><code>bun add @wrnexus/dev-server@0.2.24</code><button type="button" class="copy-button" aria-label="Copy installation command">Copy</button></pre><p><a href="/access">Request preview access</a>. Never put registry tokens in source control.</p></section></section><section id="guide" class="prose"><blockquote>The WRNexusJS HTTP + WebSocket server runtime — request dispatch, SSR document assembly, live-reload (HMR), and the portable production handler.</blockquote>
<p>Part of the <strong>WRNexusJS</strong> framework — an SSR-first, Bun-native full-stack web framework.</p>
<h3 id="overview">Overview</h3>
<p>This package is the server runtime that powers a WRNexusJS app in both development and production. A single <strong>request runtime</strong> (<code>createHandlers</code>) owns HTTP/WebSocket dispatch and SSR document assembly; it knows nothing about _how_ modules and assets are produced, so the dev and prod entry points wire in different backends: dev uses dynamic module loading plus on-the-fly bundling and injects a live-reload client; prod uses a static, pre-built manifest with cache-immutable assets. The package also ships a multi-app <strong>gateway</strong> (route several apps by <code>Host</code> header behind one port) and a portable <code>node:http</code> adapter for WinterCG hosts. It is entirely server-side and Bun-native (<code>Bun.serve</code>, <code>Bun.file</code>, <code>Bun.gzipSync</code>).</p>
@@ -652,88 +652,47 @@ interface RunningServer &#123;
declare function startServer(opts: ServeOptions): Promise&lt;RunningServer&gt;;
export &#123; type AssetServer, type FetchHandler, type GatewayApp, type GatewayAuth, type GatewayOptions, type GatewaySecurity, RESTART_EXIT_CODE, type RunningGateway, type RunningServer, type RuntimeDeps, type ServeOptions, type WsData, createHandlers, createProductionHandlers, createProductionServer, nodeListener, serveNode, startGateway, startServer, toRequest, writeResponse &#125;;
</code></pre></section><section id="examples" class="prose examples"><h2>Examples</h2><p>Examples are taken from this package's installed documentation and must be evaluated with its requirements and stability notes.</p><div class="example-grid"><article class="example-card"><h3>Example 1</h3><pre data-language="bash"><code>bun add @wrnexus/dev-server</code></pre></article><article class="example-card"><h3>Example 2</h3><pre data-language="ts"><code>interface ServeOptions &#123;
appDir: string; // absolute/relative path to the app/ dir
port?: number; // default 3000
hostname?: string; // default &quot;localhost&quot;
mode?: Mode; // &quot;development&quot; | &quot;production&quot;; default &quot;development&quot;
hmr?: boolean; // inject live-reload client; default (mode === &quot;development&quot;)
styleEntry?: string | null; // resolved absolute path to the global CSS entry
stylesConfig?: StylesConfig; // custom styles processor (e.g. Tailwind/PostCSS)
head?: string; // raw HTML appended to every page &lt;head&gt;
seo?: SeoConfig; // global SEO defaults
security?: SecurityConfig; // security headers + CORS policy
theme?: ThemeConfig; // design-token theme (merged over built-in light/dark)
i18n?: I18nConfig; // default language + supported locales
db?: &#123; driver: string; url: string &#125;; // default db → getDb(); dev auto-migrates
databases?: Record&lt;string, &#123; driver: string; url: string &#125;&gt;; // named dbs → getDb(&quot;&lt;name&gt;&quot;)
realtime?: &#123; scale?: boolean; redisUrl?: string &#125;; // bridge rooms over Redis across processes
&#125;
</code></pre></section><section id="examples" class="prose examples"><h2>Examples</h2><p>Examples are taken from this package's installed documentation and must be evaluated with its requirements and stability notes.</p><div class="example-grid"><article class="example-card"><h3>Programmatic dev server</h3><pre data-language="ts"><code>import &#123; startServer &#125; from &quot;@wrnexus/dev-server&quot;;
interface RunningServer &#123;
port: number;
hostname: string;
url: string;
router: Router;
stop(): void;
&#125;</code></pre></article><article class="example-card"><h3>Example 3</h3><pre data-language="ts"><code>interface RuntimeDeps &#123;
mode: Mode;
hmr: boolean; // inject the live-reload client into pages
router: Router;
loadModule(file: string): Promise&lt;Record&lt;string, unknown&gt;&gt;;
getMiddleware(): Promise&lt;Middleware[]&gt;;
assets: AssetServer; // serves /__wrnexus/* (islands, reactive, hmr)
hasStyles?: boolean; // inject the global stylesheet link
hasUi?: boolean; // inject the Wire UI stylesheet (/__wrnexus/ui.css)
theme?: ResolvedTheme; // enables /__wrnexus/theme.css + &lt;html data-theme&gt;
i18n?: ResolvedI18n; // enables ctx.t, &lt;html lang&gt;, &#123;t:key&#125; markers
inlineStyles?: string; // inline small prod stylesheets into &lt;head&gt;
assetVersion?: string; // cache-busting ?v= on framework asset URLs
head?: string; // raw HTML appended to every page &lt;head&gt;
seo?: SeoConfig;
security?: SecurityConfig;
maxBodyBytes?: number; // 413 above this; default 10 MB
hub?: HmrHub; // browser HMR sockets (dev only)
realtimeBus?: RealtimeBus; // cross-process room bridge (Redis pub/sub)
&#125;
const server = await startServer(&#123;
appDir: &quot;./app&quot;,
port: 3000,
mode: &quot;development&quot;,
theme: &#123;/* design tokens */&#125;,
db: &#123; driver: &quot;sqlite&quot;, url: &quot;file:./data/app.db&quot; &#125;,
&#125;);
interface Handlers &#123;
fetch(req: Request, server: UpgradeServer): Promise&lt;Response | undefined&gt;;
websocket: &#123; open; message; close; drain &#125;;
&#125;</code></pre></article><article class="example-card"><h3>Example 4</h3><pre data-language="ts"><code>interface ProdManifest &#123;
pages: &#123; raw: string; mod: RouteModule &#125;[];
api: &#123; raw: string; mod: RouteModule &#125;[];
realtime: &#123; raw: string; mod: RouteModule &#125;[];
middleware: Middleware[];
components: &#123; name: string; mod: RouteModule &#125;[];
layouts: &#123; name: string; mod: RouteModule &#125;[];
&#125;
console.log(`Running at $&#123;server.url&#125;`);
// server.stop();</code></pre></article><article class="example-card"><h3>Production server from a build manifest</h3><pre data-language="ts"><code>import &#123; createProductionServer &#125; from &quot;@wrnexus/dev-server&quot;;
import &#123; manifest &#125; from &quot;./dist/manifest.js&quot;; // generated by `wrnexus build`
interface ProdOptions &#123;
stylesPath?: string;
inlineStyles?: string;
reactivePath?: string;
themePath?: string;
themeJsPath?: string;
theme?: ResolvedTheme;
uiCssPath?: string;
schemasJs?: string;
i18n?: ResolvedI18n;
db?: &#123; driver: string; url: string &#125;;
databases?: Record&lt;string, &#123; driver: string; url: string &#125;&gt;;
realtime?: &#123; scale?: boolean; redisUrl?: string &#125;;
assetVersion?: string;
publicDir?: string;
head?: string;
seo?: SeoConfig;
security?: SecurityConfig;
port?: number;
hostname?: string;
maxBodyBytes?: number;
&#125;</code></pre></article></div></section></article>
createProductionServer(manifest, &#123;
stylesPath: &quot;./dist/styles.css&quot;,
reactivePath: &quot;./dist/reactive.js&quot;,
assetVersion: process.env.BUILD_ID,
db: &#123; driver: &quot;postgres&quot;, url: process.env.DATABASE_URL! &#125;,
port: Number(process.env.PORT) || 3000,
&#125;);</code></pre></article><article class="example-card"><h3>Embedding the handler on node:http</h3><pre data-language="ts"><code>import &#123; createProductionHandlers, serveNode &#125; from &quot;@wrnexus/dev-server&quot;;
const handlers = createProductionHandlers(manifest, opts);
await serveNode(handlers.fetch, &#123; port: 8080 &#125;);</code></pre></article><article class="example-card"><h3>Multi-app gateway</h3><pre data-language="ts"><code>import &#123; startGateway &#125; from &quot;@wrnexus/dev-server&quot;;
await startGateway(&#123;
port: 3000,
apps: [
&#123; name: &quot;web&quot;, dir: &quot;./apps/web&quot;, domains: [&quot;localhost&quot;, &quot;web.localhost&quot;] &#125;,
&#123;
name: &quot;admin&quot;,
dir: &quot;./apps/admin&quot;,
domains: [&quot;admin.localhost&quot;],
auth: &#123; basic: &#123; user: &quot;root&quot;, pass: &quot;s3cret&quot; &#125; &#125;,
&#125;,
],
security: &#123; trustedHostsOnly: true, rateLimit: &#123; max: 600 &#125; &#125;,
&#125;);</code></pre></article></div></section></article>
<aside class="on-this-page"><h2>On this page</h2><nav><a class="toc-level-2" href="#guide">Guide</a><a class="toc-level-3" href="#overview">Overview</a><a class="toc-level-3" href="#api">API</a><a class="toc-level-4" href="#main-entry-wrnexus-dev-server">Main entry (@wrnexus/dev-server)</a><a class="toc-level-4" href="#startserver-opts">startServer(opts)</a><a class="toc-level-4" href="#createhandlers-deps">createHandlers(deps)</a><a class="toc-level-4" href="#createproductionserver-manifest-opts-createproductionhandlers-manifest-opts">createProductionServer(manifest, opts) / createProductionHandlers(manifest, opts)</a><a class="toc-level-4" href="#startgateway-opts-multi-app-gateway">startGateway(opts) — multi-app gateway</a><a class="toc-level-4" href="#node-http-adapter-from-adapters-node-ts">node:http adapter (from ./adapters/node.ts)</a><a class="toc-level-4" href="#subpath-export-wrnexus-dev-server-serve-entry">Subpath export: @wrnexus/dev-server/serve-entry</a><a class="toc-level-3" href="#usage">Usage</a><a class="toc-level-4" href="#programmatic-dev-server">Programmatic dev server</a><a class="toc-level-4" href="#production-server-from-a-build-manifest">Production server from a build manifest</a><a class="toc-level-4" href="#embedding-the-handler-on-node-http">Embedding the handler on node:http</a><a class="toc-level-4" href="#multi-app-gateway">Multi-app gateway</a><a class="toc-level-3" href="#framework-asset-routes">Framework asset routes</a><a class="toc-level-3" href="#requirements-notes">Requirements / Notes</a><a class="toc-level-2" href="#api">Complete API</a><a class="toc-level-2" href="#examples">Examples</a></nav></aside>
</main>
<footer>WRNexusJS 0.2.23 · Private Developer Preview · Bun-native · Documentation generated from installed package APIs.</footer>
<footer>WRNexusJS 0.2.24 · Private Developer Preview · Bun-native · Documentation generated from installed package APIs.</footer>
</div>
}
}