feat(web-adapter): expose serveStatic and distPath for runtime admin serving

Adds serveStatic and distPath to WebBkndConfig so the web adapter can
fully support server-side admin UI. Warns when adminOptions is set
without serveStatic. Removes false from adminOptions type to prevent
accidental runtime path with no admin benefit.
This commit is contained in:
Cameron Pak
2026-04-03 06:20:39 -05:00
parent eb6fe375b3
commit fdadca2177
+27 -3
View File
@@ -5,20 +5,44 @@ import {
} from "bknd/adapter";
import type { AdminControllerOptions } from "modules/server/AdminController";
import type { App } from "App";
import type { MiddlewareHandler } from "hono";
import { $console } from "bknd/utils";
export type WebBkndConfig<Env = Record<string, string | undefined>> = FrameworkBkndConfig<Env> & {
adminOptions?: AdminControllerOptions | false;
/**
* Serve the admin UI from the server. When omitted, render the admin UI
* client-side via `import { Admin } from "bknd/ui"` and `import "bknd/dist/styles.css"`.
*
* When provided, also set up static asset serving via one of:
* - `serveStatic` middleware (for Bun, Node, etc.)
* - `bknd copy-assets --out <static-dir>` postinstall script
* - `serveStaticViaImport()` from `bknd/adapter` (for edge/serverless)
*/
adminOptions?: AdminControllerOptions;
/** Hono middleware for serving bknd's bundled JS/CSS assets. */
serveStatic?: MiddlewareHandler | [string, MiddlewareHandler];
/** Override the path to bknd's dist folder (default: ./node_modules/bknd/dist) */
distPath?: string;
};
export function createBknd<Env>(config: WebBkndConfig<Env>, args?: Env) {
let appPromise: Promise<App> | undefined;
const { adminOptions, ...frameworkConfig } = config;
const { adminOptions, serveStatic, distPath, ...frameworkConfig } = config;
async function getApp() {
if (!appPromise) {
if (adminOptions != null) {
appPromise = createRuntimeApp({ ...frameworkConfig, adminOptions }, args);
if (!serveStatic) {
$console.warn(
"adminOptions provided without serveStatic — admin UI assets may not be served. "
+ "See serveStatic, bknd copy-assets, or serveStaticViaImport.",
);
}
appPromise = createRuntimeApp(
{ ...frameworkConfig, adminOptions, serveStatic, distPath },
args,
);
} else {
appPromise = createFrameworkApp(frameworkConfig, args);
}