Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
createWorker is the glue that assembles your Baseflare backend into a deployable Cloudflare Worker. It accepts a BaseflareManifest object describing your schema, permission rules, server functions, and optional HTTP router, and returns an ExportedHandler — a Cloudflare Workers-compatible object with a fetch method. The return value is meant to be the default export of your Worker entry file.
Signature
BaseflareManifest
The validated schema returned by
defineSchema(). Used to resolve table
definitions for write validation and to power the D1 DDL during deployment.Permission rules returned by
defineRules(). If omitted, all database
operations across all tables are denied. Pass an empty object {} only if
you intend for all tables to be inaccessible from client-callable functions
(e.g. a server-functions-only architecture using only internal functions).Public query function entries. Typically assembled by the CLI’s code generation
step from your functions directory. Each entry carries the function definition,
its export name, module path, and canonical name.
Public mutation function entries.
Public action function entries.
Internal query function entries. Not reachable via HTTP — only via
ctx.runQuery().Internal mutation function entries. Not reachable via HTTP — only via
ctx.runMutation().Internal action function entries. Not reachable via HTTP — only via
ctx.runAction().An optional
HttpRouter instance created with httpRouter(). Registers
custom HTTP endpoints that are dispatched after the built-in RPC routes.Optional project configuration returned by
defineConfig(). Controls CORS
policy, request limits, and Cloudflare Worker settings at runtime.Example Worker Entry Point
Request Routing Order
createWorker evaluates each incoming request against routes in this order:
POST /api/query/:name— looks up a public query by canonical name and executes it with a read-only database context.POST /api/mutation/:name— looks up a public mutation and executes it in a serializable D1 transaction.POST /api/action/:name— looks up a public action and executes it with an action context (no directctx.db).- Custom HTTP routes — if a
httprouter is provided,router.lookup(method, pathname)is called; the first matching handler (exact before prefix) is invoked. - 404 — if nothing matches, a structured JSON
404 Not Foundresponse is returned.
RPC routes only accept
POST. Sending a GET to /api/query/myQuery returns
a 400 Bad Request with a descriptive error explaining that the RPC method
requires POST.BaseflareRuntimeEnv
The Worker bindings Baseflare requires in the Cloudflare environment object:
The D1 database binding. Configure it in
wrangler.toml:Additional bindings such as R2 (file storage), Durable Objects (real-time
subscriptions), and Vectorize (vector search) are planned for Phase 2+.
Error Handling
createWorker wraps the entire request lifecycle in a try/catch. Errors are converted to structured JSON responses:
| Error type | HTTP status |
|---|---|
ValidationError / SchemaError / malformed request | 400 Bad Request |
| Not-found function or route | 404 Not Found |
| Permission denied | 403 Forbidden |
| Unexpected / unhandled error | 500 Internal Server Error |
RuntimeError, BaseflareError, ValidationError, or SchemaError) are logged to the Cloudflare Workers logging pipeline with a runtime.unexpected_error event name before the 500 response is returned.
createWorker does not run DDL. The CREATE TABLE and CREATE INDEX
statements from schema.toCreateStatements() are a deploy-time step executed
by the CLI before any traffic reaches the Worker. The schema your Worker
receives at runtime is assumed to already be applied in D1.