import { Middleware } from '../middleware'; import { Context } from '../context'; import { Component, Value, PostConstruct } from '@celljs/core'; import { BODY_MIDDLEWARE_PRIORITY, BodyOptions } from './body-protocol'; import { BodyParser } from './body-parser'; @Component(Middleware) export class BodyMiddleware implements Middleware { @Value('web.body') protected readonly options?: BodyOptions; protected parser: BodyParser; @PostConstruct() protected init(): void { this.parser = new BodyParser(this.options); } async handle(ctx: Context, next: () => Promise): Promise { await this.parser.parse(ctx.request, ctx.response); return next(); } readonly priority = BODY_MIDDLEWARE_PRIORITY; }