Examples

Example 1

import { ReactRouterPlugin } from '@setu-ts/react-router-plugin';
import { CAPABILITIES, ISsrService } from '@setu-ts/common';

const app = createApplication();
app.register(ReactRouterPlugin({
  serverBuildPath: './build/server/index.js',
  assetsDir: './build/client/assets',
}));
await app.start({ port: 3000 });

Classes

Functions

f
assembleHandler(
build: unknown,
createRequestHandler: (
build: unknown,
mode: string
) => unknown
,
mode: string
): SsrRequestHandler

Pure function that assembles an RR request handler from a pre-loaded build and the createRequestHandler factory.

f
assertSsrRuntime(value: unknown): SsrRuntime

Validates that an injected loadRequestHandler resolved to a usable SsrRuntime, and narrows it.

f
bridgeRequestToRR(
ctx: IRequestContext,
handler: SsrRequestHandler,
createLoadContext: () => RouterLoadContext,
populateLoadContext?: PopulateLoadContext
): Promise<HandlerResult>

Bridges a kernel IRequestContext into a web Request, invokes the RR handler, and maps the resulting web Response back onto ctx.response.

f
contextKeyFor<T>(
name: string,
defaultValue: T
): RouterContextKey<T>

Returns the context key for a name, creating it on first use.

f
createLoadContextFactory(rr: Record<string, unknown>): () => RouterLoadContext

Builds the per-request context factory from React Router's RouterContextProvider class.

f
createPublicFileHandler(options: { fs: IFileSystem; assetsDir: string; }): (ctx: IRequestContext) => Promise<HandlerResult | undefined>

Creates a handler that ATTEMPTS to serve a file from a directory, resolving the request path relative to createPublicFileHandler.options.assetsDir. The plugin passes the CLIENT-BUILD ROOT here (the parent of the assets dir, where Vite copies public/) — probing the assets subdir itself missed every public file.

f
createStaticAssetHandler(options: { fs: IFileSystem; assetsDir: string; assetUrlPrefix: string; }): RouteHandler

Creates a static-asset RouteHandler that serves files from a directory using the injected IFileSystem.

Interfaces

I
HandlerResult

Opaque marker returned by IResponse terminal methods and expected back from route handlers. It exists purely so the type system can verify a handler produced a response; only the kernel creates values of this type.

I
IFileSystem

Runtime-agnostic file system operations. Absent on runtimes without file system access (edge platforms).

I
IRequestContext

Per-request context passed to middleware and route handlers. Each request gets a fresh context; request-scoped data lives here, never in globals.

I
ISsrService

Service contract for server-side rendering (SSR).

I
ReactRouterPluginOptions

Options for the React Router plugin.

I
RouterContextKey

A React Router context key, used by identity as the argument to RouterLoadContext.get / RouterLoadContext.set.

I
RouterLoadContext

The per-request context object React Router passes to loaders, actions, and middleware as context.

I
SsrRuntime

Everything the plugin needs from a loaded React Router module: the request handler, plus a factory for the RouterContextProvider that handler will accept.

Type Aliases

T
PopulateLoadContext = (
ctx: IRequestContext,
context: RouterLoadContext
) => void

Hook for adding application values to the per-request React Router context.

T
RouteHandler = (ctx: IRequestContext) => HandlerResult | Promise<HandlerResult>

A route handler: receives the request context and returns a response via the context's response builder.

T
SsrRequestHandler = (
request: Request,
loadContext: unknown
) => Promise<Response>

React Router request handler — the callable returned by createRequestHandler(build, mode).

Variables

v
CAPABILITIES: { RUNTIME: string; LOGGER: string; CONFIG: string; VALIDATION: string; DATABASE: string; CACHE: string; EVENTS: string; MESSAGING: string; AUTH: string; AUTHORIZATION: string; JWT: string; SCHEDULER: string; METRICS: string; HEALTH: string; OPENAPI: string; TELEMETRY: string; SECRETS: string; AUDIT: string; RESILIENCE: string; STORAGE: string; MAIL: string; NOTIFICATION: string; FEATURE_FLAGS: string; QUEUE: string; CQRS: string; COMMAND_BUS: string; QUERY_BUS: string; MULTI_TENANCY: string; WORKER_POOL: string; DI_CONTAINER: string; HTTP_ADAPTER: string; SSE: string; WEBSOCKET: string; REALTIME_BACKPLANE: string; SSR: string; SESSION: string; SERVICE_DISCOVERY: string; HEALTH_INDICATOR: string; METRIC_REGISTRATION: string; OPENAPI_SCHEMA: string; CLI_COMMAND: string; DECORATOR_HANDLER: string; METADATA_STORE: string; GRPC: string; CLOUDFLARE: string; GRAPHQL: string; STATIC_FILES: string; VIEW: string; }

Standard capability tokens provided by the first-party plugins.

v
servicesContext: RouterContextKey<IServiceRegistry | null>

Key holding the kernel IServiceRegistry for the current request.

v
userContext: RouterContextKey<IPrincipal | null>

Key holding the authenticated principal, or null on an anonymous request.