![NPM](https://camo.githubusercontent.com/b6179fe1fd508deb206d6f91c9d3f74d85ea598136a2011e81006a6c35913eb4/68747470733a2f2f736869656c64732e696f2f6e706d2f762f406372616e2f6c69622e6b6f612e636f72653f6c6f676f3d6e706d267374796c653d666f722d7468652d6261646765266c6162656c3d26636f6c6f723d433830303030)
- 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>;
}
}