nfp_sites/api/middlewares/mask.mjs
2019-09-13 13:33:10 +00:00

18 lines
385 B
JavaScript

import jsonmask from 'json-mask'
export function mask() {
return async function(ctx, next) {
await next()
let body = ctx.body
let fields = ctx.query['fields'] || ctx.fields
if (!body || 'object' != typeof body || !fields) return
if (body && body.toJSON) {
body = body.toJSON()
}
ctx.body = jsonmask.filter(body, jsonmask.compile(fields))
}
}