Skip to main content

Key Differences from Core Documentation

CrumbJS for Cloudflare Workers runs on V8 instead of Bun. This makes the implementation independent from the core version.
About 90% of the core documentation still applies—this section only highlights the main differences.

MongoDB and Queues​

  • Not supported in this version.
    Cloudflare Workers do not support the TCP connections required by MongoDB and BullMQ.

App Instance Type Parameters​

Specifying type parameters is optional. You may use env as any, but typing is recommended for better DX.

type Vars = {
user?: User;
};

const app = new App<Env, Vars>();

app.use(async ({ set, next }) => {
set("user", { id: 1, name: "Elias" }); // strongly typed
return await next();
});

app.get("/me", ({ getOrFail }) => {
return getOrFail("user"); // typed and non-null
});

// Example with D1 binding
app.post("/", async ({ env }) => {
const companyName1 = "Bs Beverages";
const companyName2 = "Around the Horn";
const stmt = env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?");
return await env.DB.batch([stmt.bind(companyName1), stmt.bind(companyName2)]);
});

Middleware​

Signals middleware is not required.
Wrangler already provides the request tracking and logging that Signals was designed for.

Routing​

The Cloudflare Workers version of CrumbJS uses rou3, a very fast router with small differences:

app.get("/wild/**", handler); // Matches all paths after /wild

Proxies can target Cloudflare service bindings!!:

/** AUTH is the name of the destination service binding (env.AUTH) */

app.proxy('POST', '/auth', "AUTH", { body: authRequestDto, use: [guestMiddleware] });
app.proxyAll("/auth", "AUTH");

// Also support external url destination as core
app.proxy(
'POST',
'/auth',
'https://auth-ms.example.com/v1/auth', // FQDN url
{ body: authRequestDto, use: [guestMiddleware] }
);

app.proxyAll('/v1', 'https://microservice-a.example.com/v1', [authMiddleware]);

Static Assets​

Static routes are not supported.
Use static asset bindings instead.

Configuration​

Not all configuration can be injected through env, since env is bound to each request in Cloudflare Workers.
The only overridable variable is APP_MODE, which controls the log level of the logger utility.

End-to-End Type Safety​

  • Not automatically generated at server startup.
    Cloudflare’s V8-like runtime does not allow it.
  • You can still use openapi-ts to generate types.
  • We are developing scripts to make this process easier.

Note: We are working on a dedicated Cloudflare-specific documentation set, even if it requires repeating parts of the core docs.