- First-class integration with @koa/router
- Prometheus telemetry by prom-client
- Health endpoint conforming to rfc-healthcheck
- CORS management by @koa/cors
- Security provided by koa-helmet
- Data compression by koa-compress
- Default body parsing by koa-bodyparse
- Response time tracking by koa-response-time
npm install @cran/lib.koa.core koa prom-client
import { Server } from "@cran/lib.koa.core";
void (async function main ( ) {
const server = await new Server().start();
console.log(server.getNetwork().address());
})().catch(console.error);
import { Server, Router } from "@cran/lib.koa.core";
const router = new Router("/");
// register router handlers
async function middleware ( ctx, next ) {
// do middleware things
await next();
}
const server = new Server()
.use(middleware)
.useRouter(router);
void (async function main ( ) {
await server.start();
console.log(server.getNetwork().address());
})().catch(console.error);
new Server(options as Server.Options);
export namespace Server {
export interface SystemRouterOptions<State, Context> {
// defaults to `/-`
prefix?: string;
// custom health path and check function
health?: false | string | { path: string; } & health.Options;
// custom metrics path
metrics?: false | string | { path: string; };
}
export interface Options<State, Context> {
// useful for HTTPS cert configuration
network?: HttpServer | HttpsServer;
// https://www.npmjs.com/package/@koa/cors
cors?: false | cors.Options;
// https://www.npmjs.com/package/koa-bodyparser
bodyParser?: false | bodyParser.Options;
// https://www.npmjs.com/package/koa-helmet
helmet?: false | helmet.Options;
// https://www.npmjs.com/package/koa-response-time
responseTime?: false | responseTime.Options;
// https://www.npmjs.com/package/koa-compress
compress?: false | compress.Options;
// see above
systemRouter?: SystemRouterOptions<State, Context>;
}
}