Skip to content

Cloudflare Worker ​

Typed routing, worker setup, and response helpers for Cloudflare Workers. The package is intended for Worker projects that want typed route definitions with path parameters, predictable response helpers, and a ready-made module export without adopting a larger framework.

Categories ​

  • Routing — defineRoute creates typed method route definitions, and compileRoutes turns a route collection into a sorted, matchable route list.
  • Scheduling — defineScheduled declares a task for a cron expression, and compileScheduled merges every task registered for the same expression.
  • Worker — createWorker builds the fetch and scheduled module export, dispatching requests, falling back to static assets, running scheduled tasks, and handling errors.
  • Response — HttpResponse adds a from() factory for forwarding an upstream response to the shared @almighty-shogun/http-core class, whose methods create responses for JSON, HTML, text, images, redirects, and common status responses such as not found and too many requests.
  • Types — the augmentable WorkerEnv interface, route and request type helpers, and worker option types.
  • Errors — the scheduled collection failures raised while compiling tasks, and the aggregate raised when tasks fail.

Dependencies ​

  • Cloudflare Workers runtime — required for ExecutionContext, ScheduledController, and the Fetch API primitives the package builds on.
  • @almighty-shogun/http-core — a direct dependency providing the HTTP vocabulary, the query helpers, the error classes, and the response class.
  • @almighty-shogun/utils — a direct dependency, used for shared utility types only and never at runtime.

This package targets the Workers runtime. It does not use Node APIs, a filesystem, or a persistent process, so it does not run under Node.js or Bun without a Workers-compatible host.

Quick example ​

ts
import {
    createWorker,
    defineRoute
} from '@almighty-shogun/cloudflare-worker';

const routes = {
    health: defineRoute('/health', 'GET', (_, response) => {
        return response.json({ ok: true });
    })
};

export default createWorker({ routes });

Continue with installation or jump to a category from the sidebar.

All packages are released under the MIT License.