@mtth/stl-koa
v0.9.7
Published
Koa utilities
Downloads
33
Readme
@mtth/stl-koa
Koa glue code with telemetry, throttling, request metrics, and graceful binding helpers tailored for backend services.
Quickstart
pnpm add koa @koa/router @mtth/stl-koaimport Koa from 'koa';
import Router from '@koa/router';
import {AppTelemetry} from '@mtth/stl-bootstrap';
import {AppBindable, setup} from '@mtth/stl-koa';
const telemetry = AppTelemetry.create({name: 'example-api'});
const app = new Koa();
app.use(setup({telemetry}));
const router = new Router();
router.get('/healthz', (ctx) => {
ctx.body = {status: 'ok'};
});
app.use(router.routes());
const bindable = AppBindable.create({app, telemetry});
bindable.start(); // binds to $APP_PORT or 8080The setup middleware automatically records HTTP metrics, propagates trace ids,
and normalizes error responses. AppBindable wires the server into the
Bindable lifecycle so SIGTERM triggers a graceful shutdown.
Highlights
setup()applies a full stack of instrumentation: structured logging, request metrics (http.server.*), tracing, error sanitization, and client IP extraction in a single middleware.AppBindablebinds any Koa app to an HTTP server with telemetry-aware log messages, default port discovery, and automatic signal handlers.- Rate-limiting + throttling helpers build on
rate-limiter-flexiblewith typed errors and OTEL metrics. - Streaming helpers, health utilities, and codec helpers (brotli JSON, raw body decoding) cover the boring but necessary HTTP plumbing so routes stay clean.
