Skip to main content

Server Options

The Burger constructor accepts a ServerOptions object. These are the main options:

OptionTypeDescription
apiDirstringDirectory containing API route files (e.g. ./src/api). Defaults to ./src/api in filesystem mode when that directory exists. Relative to the project root, with an entry-file fallback (src/) when the CLI loads or scans the app. See How directories resolve.
apiRoutesRouteDefinition[]Pre-built API routes from the CLI build. When present, apiDir is ignored and no runtime filesystem scan happens.
pageDirstringDirectory for page files. Defaults to ./src/pages when that directory exists.
pageRoutesPageDefinition[]Pre-built page routes from the CLI build. When present, pageDir is ignored.
wsDirstringDirectory for WebSocket route files. Defaults to ./src/websocket when that directory exists, so file-based WS routes work in dev without configuration.
wsRoutesWebSocketRouteDefinition[]Pre-built WebSocket routes from the CLI build. When present, wsDir is ignored.
assetRoutesEmbeddedAsset[]Embedded static assets from the CLI build (files under <pageDir>/assets/). When present, assets are served from the table; otherwise dev reads them from disk under pageDir.
apiPrefixstringURL prefix for API routes (default: 'api'; '' mounts them at /).
pagePrefixstringURL prefix for page routes (default: '').
titlestringFallback API title for the OpenAPI document when no openapi.config.ts exists. Prefer OpenAPI config.
descriptionstringFallback API description, same rules as title.
versionstringFallback API version, same rules as title.
debugbooleanEnable debug mode (richer error rendering, response-validation detail). Defaults to on when NODE_ENV=development (the CLI dev command sets it); false turns it off even in development.
validationobjectValidation settings: coerce (boolean), responseValidation ('off' | 'dev' | 'enforce'), errorFormat ('plain' | 'problem+json'), status (number), errorRenderer. See Validation Configuration.
openapiOpenAPIConfigOpenAPI configuration for programmatic apps. In dev, openapi.config.ts is auto-discovered; burger-api build embeds the convention file, so you rarely set this. See OpenAPI.
globalHooksRecord<string, unknown>Pre-resolved global hooks module (from src/hooks.ts). Used in production builds with apiRoutes; in dev, src/hooks.ts is auto-discovered and this field is ignored.
pluginsModuleRecord<string, unknown>Pre-resolved plugins module (from src/plugins.ts). In dev, src/plugins.ts is auto-discovered.
providersModuleRecord<string, unknown>Pre-resolved providers module (from src/providers.ts). In dev, src/providers.ts is auto-discovered.
jitbooleanJIT-compile each route's hook plan into one function. Default true; runtimes that forbid dynamic code generation keep the interpreter. Set false to opt out.
engine'auto' | 'regex' | 'trie'Dynamic-route dispatch engine for the fetch fallback. Default 'auto' (trie). Static dispatch is unaffected.
hostnamestringHostname to bind for serve().
adapterRuntimeAdapterRuntime adapter override (test/embed seam). Defaults to the Bun adapter, loaded on first serve().
runtimeTargetRuntimeTargetDeployment target this build was produced for. Set automatically by burger-api build --target=<platform>; resolves WebSocket upgrade handling on targets that cannot be detected at runtime.
maxRequestBodySizenumberMaximum request body size in bytes for serve() (Bun's default is 128 MB). Larger bodies are rejected by the runtime with 413.

Dev vs production​

In filesystem mode you pass apiDir/pageDir/wsDir, or let them default to the conventions (./src/api, ./src/pages, ./src/websocket) when those directories exist. Production builds pass the prebuilt apiRoutes/pageRoutes/wsRoutes instead. The CLI build produces the AOT route tables: burger-api build embeds them into the bundle, so production never scans the filesystem at runtime. See CLI Tool and Burger Class.

Types for this feature​

The options object is typed as ServerOptions. TypeScript checks every option you pass.

The types you use (all from burger-api):

  • ServerOptions: the options of new Burger({...})
  • RouteDefinition: a route for apiRoutes
  • RouteSchema: a route's full schema map
  • HTTPMethod: the allowed method names

✅ Correct, typed options and a typed route definition:

import { Burger } from "burger-api";
import type { RouteDefinition } from "burger-api";

const routes: RouteDefinition[] = [
{
path: "/users",
handlers: { GET: (ctx) => Response.json({ ok: true }) },
},
];

const app = new Burger({
apiDir: "./src/api",
apiRoutes: routes,
debug: true,
});

❌ Wrong, an unknown option or a bad method key:

new Burger({
apiDir: "./src/api",
apiDri: "./src/api", // ❌ Property 'apiDri' does not exist
});

const bad: RouteDefinition = {
path: "/x",
handlers: { Get: () => new Response() }, // ❌ 'Get' is not an HTTP method
};

See the TypeScript overview.

Check your code: bun run typecheck.