mock
constmock: (config?) =>Policy
Defined in: src/policies/mock.ts:62
Return a static mock response, bypassing the upstream entirely.
Useful for development stubs, testing, and placeholder routes. Runs at
priority 999 (always last) and short-circuits — next() is never called,
so no upstream request is made. Object bodies are automatically
JSON-serialized with content-type: application/json.
Parameters
Section titled “Parameters”config?
Section titled “config?”MockConfig
Status code, response body, headers, and artificial delay. All fields optional.
Returns
Section titled “Returns”A Policy at priority 999 (replaces the upstream).
Example
Section titled “Example”import { createGateway } from "@homegrower-club/stoma";import { mock } from "@homegrower-club/stoma/policies";
createGateway({ routes: [{ path: "/api/stub", pipeline: { policies: [ // Return a JSON stub with 200ms simulated latency mock({ body: { message: "Hello from stub" }, delayMs: 200, }), ], upstream: { type: "handler", handler: () => new Response() }, // never reached }, }],});
// Simulate a 503 maintenance pagemock({ status: 503, body: "Service temporarily unavailable", headers: { "retry-after": "300" },});