import type { App } from "bknd"; import { type FrameworkBkndConfig, createFrameworkApp } from "bknd/adapter"; import { Api } from "bknd/client"; export type RemixBkndConfig = FrameworkBkndConfig; type RemixContext = { request: Request; }; let app: App; export function serve( config: RemixBkndConfig = {} ) { return async (args: Args) => { if (!app) { app = await createFrameworkApp(config, args); } return app.fetch(args.request); }; } export function withApi( handler: (args: Args, api: Api) => Promise ) { return async (args: Args) => { if (!args.context.api) { args.context.api = new Api({ host: new URL(args.request.url).origin, headers: args.request.headers }); await args.context.api.verifyAuth(); } return handler(args, args.context.api); }; }