createApp<Env>() is the entry point for every Blaze application. It returns a fully-configured app instance with Express-style routing methods, a composable middleware stack, and the app.fetch handler you export directly to the Cloudflare Workers runtime. Providing your Env type once here propagates type safety through every route, middleware, and sub-router in your app.
Creating an app
Pass your typedEnv interface — mirroring the bindings declared in wrangler.toml — as the generic argument to createApp. Export app.fetch as the fetch property of the module’s default export to wire it into the Workers runtime.
Always use
export default { fetch: app.fetch } (Module Worker syntax) rather
than addEventListener('fetch', …). Module Workers have lower cold-start
latency and get first-class access to env bindings.App methods
Every method on the app object returnsapp (except app.Router(), which returns a new sub-router, and app.fetch / app.scheduled, which are the Workers entrypoints), so you can chain registrations fluently.
Registering routes
Use the HTTP-method shortcuts to register routes. Each accepts the path pattern followed by one or more handler functions. When you pass multiple handlers, Blaze runs them as an inline middleware stack for that route — each must callnext() to continue.
Inline middleware on a route
Pass multiple functions to add per-route middleware — useful for auth guards or validators that apply to a single endpoint:Mounting middleware
app.use() registers middleware that runs for every request, or — when you supply a path prefix — for requests whose URL starts with that prefix.
1
Global middleware
Middleware registered without a path prefix runs on every request, in registration order:
2
Path-scoped middleware
Middleware registered with a path prefix runs only when the request URL begins with that prefix. The prefix is stripped from
req.path inside the middleware, mirroring Express behaviour:3
Custom middleware
Write middleware as any
(req, res, next) function and pass it to app.use():Route chaining
app.route(path) returns a chainable Route object. Register multiple HTTP methods on the same path without repeating the path string:
Scheduled (cron) support
Blaze exposesapp.scheduled as a second Workers entrypoint. Export it alongside app.fetch to handle Cloudflare Cron Triggers declared in wrangler.toml.
wrangler.toml
src/index.ts
The default
app.scheduled implementation is a no-op. Override it by
replacing app.scheduled with your own async (event, env, ctx) => void
function, or handle cron logic inline in the export:Not found handler
app.notFound() registers a handler called when the router exhausts its entire layer stack without sending a response. The built-in default returns { error: 'Not Found' } with a 404 status.