function createPublicFileHandler
Since 0.2.0
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.

Returns the served HandlerResult on a hit — including the 400 answer for an undecodable request path — and undefined on a miss so the caller can fall through to the next handler (the SSR catch-all).

Successful responses carry Cache-Control: public, max-age=0, must-revalidate: root files are not content-hashed, so an immutable year would serve stale content the browser refuses to re-check.

Parameters

options: { fs: IFileSystem; assetsDir: string; }

Configuration

Return Type

(ctx: IRequestContext) => Promise<HandlerResult | undefined>

An attempt handler resolving to a result, or undefined on a miss

Usage

import { createPublicFileHandler } from "react-router-plugin/src/index.ts";