Add middlewares for API and various improvements (#685)

This commit is contained in:
Henry Wang
2018-09-12 05:00:47 +01:00
committed by DIYgod
parent 05ca3a6930
commit c835fa5c02
6 changed files with 247 additions and 48 deletions

View File

@@ -0,0 +1,13 @@
module.exports = async (ctx, next) => {
await next();
if (ctx.request.path.startsWith('/api/')) {
if (ctx.body.counter > 0) {
return ctx.res.ok({
message: `request returned ${ctx.body.counter} ${ctx.body.counter > 1 ? 'routes' : 'route'}`,
data: ctx.body.result,
});
} else {
return ctx.res.noContent();
}
}
};