Skip to content

createGateway

createGateway(config): GatewayInstance

Defined in: src/core/gateway.ts:93

Create a gateway instance from a declarative configuration.

Registers all routes on a Hono app, builds per-route policy pipelines (merging global + route-level policies), and wires up upstream dispatch. Returns a GatewayInstance whose .app property is the Hono app ready to be exported as a Cloudflare Worker default export.

GatewayConfig

Full gateway configuration including routes, policies, and options.

GatewayInstance

A GatewayInstance with the configured Hono app.

If no routes are provided.

import { createGateway, jwtAuth, rateLimit } from "@homegrower-club/stoma";
const gateway = createGateway({
name: "my-api",
basePath: "/api",
routes: [
{
path: "/users/*",
pipeline: {
policies: [jwtAuth({ secret: env.JWT_SECRET }), rateLimit({ max: 100 })],
upstream: { type: "url", target: "https://users-service.internal" },
},
},
],
});
export default gateway.app;