This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/api/middlewares/apiWrapper.js

21 lines
342 B
JavaScript
Raw Normal View History

// @flow
import { type Context } from 'koa';
export default function apiWrapper() {
return async function apiWrapperMiddleware(
ctx: Context,
next: () => Promise<void>
) {
2016-09-11 20:38:52 +00:00
await next();
const ok = ctx.status < 400;
2016-09-11 20:38:52 +00:00
// $FlowFixMe
2016-09-11 20:38:52 +00:00
ctx.body = {
...ctx.body,
2016-09-17 21:53:30 +00:00
status: ctx.status,
ok,
2016-09-11 20:38:52 +00:00
};
};
}