@fluixi/server
v1.0.0-alpha.57
Published
Server-side rendering for Fluixi — request-scoped, streaming, framework-agnostic.
Readme
@fluixi/server
Server-side rendering for Fluixi — request-scoped, streaming, framework-agnostic.
✨ Overview
The universal string renderer lives in @fluixi/dom (renderToString +
request-scoping); @fluixi/server is the Node-side home that makes it
concurrency-safe and ergonomic:
- injects an
AsyncLocalStorageinto@fluixi/dom's request store so concurrent SSR requests are isolated (@fluixi/domstays browser-safe by never importingnode:async_hooksitself); - re-exports the SSR surface (
renderToString,renderToStringAsync,getRequestEvent, the request-context primitives); - adds request helpers (
renderRequest,renderRequestAsync,renderRequestToPage,renderToBodyStream,startServer,createHtmlDocument).
No meta-framework coupling — SSR is a plain function you call from any server (Express,
Hono, a worker, or @fluixi/start).
📦 Installation
pnpm add @fluixi/server🚀 Usage
import { startServer } from '@fluixi/server';
import App from './app';
const { render, page, renderAsync, stream } = startServer(App);
// express: res.send(page(req.url))Async data (Suspense / resources)
renderRequestAsync (and startServer().renderAsync) await data loaders before
serializing, then emit a window.__FX_DATA__ script so the client seeds resources
without refetching:
import { renderRequestAsync } from '@fluixi/server';
const html = await renderRequestAsync(App, { url });Streaming
import { renderToBodyStream } from '@fluixi/server';
// a web ReadableStream of the app body — the host owns the surrounding document
export const renderStream = (url) => renderToBodyStream(App, { url });Request-scoped data + redaction
import { getRequestEvent, setDataRedactor } from '@fluixi/server';
// inside a component / loader:
getRequestEvent()?.request; // the web Request (headers, cookies, …)
// strip server-only fields from __FX_DATA__ before they reach the page:
setDataRedactor((v) => (v?.passwordHash ? { ...v, passwordHash: undefined } : v));