Cloudflare Workers
An app deployed as a Cloudflare module worker: app.ts holds the routes, worker.ts is the module the Workers runtime calls, and wrangler.jsonc configures the deployment.
ts
import { App, defineCoreHandler } from 'routup';
export const app = new App();
app.get('/', defineCoreHandler(() => 'Hello from Workers'));worker.ts:
ts
import { serve } from 'routup/cloudflare';
import { app } from './app.ts';
export default serve(app, { manual: true });wrangler.jsonc:
jsonc
{
"name": "routup-example",
"main": "worker.ts",
"compatibility_date": "2026-11-01"
}Try It
Install routup and wrangler, put the three files in one folder and start the local Workers runtime:
bash
npx wrangler devbash
curl http://localhost:8787/
# Hello from WorkersHow It Works
- A module worker's default export is an object with a
fetch(request, env, ctx)method.serve(app, { manual: true })fromroutup/cloudflarereturns a server whosefetchhas that signature and passes the request toapp.fetch(). See Runtime Environments for the entry each runtime loads. manual: truekeepsserve()from registering afetchevent listener withaddEventListener(), the Service Worker format.- A handler reaches the bindings (KV, D1, secrets) as
event.request.runtime?.cloudflare?.envand the execution context asevent.request.runtime?.cloudflare?.context. With the defaulttrustProxy,getRequestIP(event)returns thecf-connecting-ipheader.