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.
2021-08-29 13:25:06 -07:00

28 lines
508 B
JavaScript

// @flow
import stream from "stream";
import { type Context } from "koa";
export default function apiWrapper() {
return async function apiWrapperMiddleware(
ctx: Context,
next: () => Promise<*>
) {
await next();
const ok = ctx.status < 400;
if (
typeof ctx.body !== "string" &&
!(ctx.body instanceof stream.Readable)
) {
// $FlowFixMe
ctx.body = {
// $FlowFixMe
...ctx.body,
status: ctx.status,
ok,
};
}
};
}