/** * Server bridge for the file-route convention. * * Turns the `action` (and optionally `load`) functions attached to file routes * into `server` routes, so a `
` posting to a route (or a `formAction()` * fetch) reaches the matching `action`. Loaders keep running before render via * the SSR router bridge; this module is specifically about the mutation/POST * side and an optional JSON loader endpoint for client-side data fetching. * * It depends only on the file-route *types* from `@bquery/bquery/router`, so it * adds no runtime coupling — pass it the `entries` from `createFileRoutes()`. * * @module bquery/server */ import type { FileRoute } from '../router/file-routes/types'; import type { ServerApp, ServerMiddleware, ServerRoute } from './types'; /** Options for {@link createFileRouteServerRoutes} / {@link mountFileRoutes}. */ export interface FileRouteServerOptions { /** * HTTP method(s) the generated action endpoint responds to. * @default 'POST' */ actionMethod?: string | string[]; /** * When set, also generate a loader endpoint serving each route's `load` * result as JSON. The pattern is `${dataPath}` (e.g. `/__data/users/:id`) * so it never collides with the HTML route. Disabled by default. */ dataPath?: string; /** Prefix prepended to every generated route path. */ basePath?: string; /** Middleware applied to generated action routes (e.g. `csrf()`). */ middlewares?: ServerMiddleware[]; /** Middleware applied to generated loader routes. */ dataMiddlewares?: ServerMiddleware[]; } /** * Build `server` route definitions from file-route entries. Routes whose module * is statically known to export no `action` (eagerly-imported modules) are * skipped; lazily-imported routes always get an endpoint that resolves the * module and replies `405` when no `action` is present. * * @example * ```ts * import { createServer, csrf } from '@bquery/bquery/server'; * import { createFileRoutes } from '@bquery/bquery/router'; * * const { entries } = createFileRoutes(import.meta.glob('./routes/**\/+page.ts')); * const app = createServer(); * for (const route of createFileRouteServerRoutes(entries, { middlewares: [csrf()] })) { * app.add(route); * } * ``` */ export declare const createFileRouteServerRoutes: (entries: FileRoute[], options?: FileRouteServerOptions) => ServerRoute[]; /** * Register the generated file-route endpoints on a server app and return the * app for chaining. * * @example * ```ts * const app = mountFileRoutes(createServer(), entries, { middlewares: [csrf()] }); * ``` */ export declare const mountFileRoutes: (app: ServerApp, entries: FileRoute[], options?: FileRouteServerOptions) => ServerApp; //# sourceMappingURL=file-routes.d.ts.map