import koa from 'koa'; import Counter from '../../helper/Counter'; type MiddlewareOptions = { counter: Counter; }; export default function countUp(options: MiddlewareOptions): koa.Middleware { const { counter } = options; return async function(ctx: koa.Context, next): Promise { const key = ctx.request.path.split('/').slice(-1)[0]; counter.countUp(key); await next(); }; }