alp-body-parser
Version:
body parser in alp framework
31 lines (28 loc) • 815 B
JavaScript
import parse from 'co-body';
const assertBodyNotParsed = (ctx) => {
if (ctx.request.body) {
throw new Error("Request is already parsed");
}
};
function alpBodyParser(app) {
app.context.parseBody = async function parseBody() {
assertBodyNotParsed(this);
const body = await parse.form(this);
this.request.body = body;
return body;
};
app.context.parseBodyJson = async function parseBodyJson() {
assertBodyNotParsed(this);
const body = await parse.json(this);
this.request.body = body;
return body;
};
app.context.parseBodyText = async function parseBodyText() {
assertBodyNotParsed(this);
const body = await parse.text(this);
this.request.body = body;
return body;
};
}
export { alpBodyParser as default };
//# sourceMappingURL=index-node.mjs.map