import {EBodyType, RawBodyType} from "@gongt/ts-stl-library/request/request"; export function initBodyParser(type: EBodyType, limit: number|string = '1000kb') { const bodyParser = require("body-parser"); if (type === EBodyType.TYPE_JSON) { return bodyParser.json({ limit: limit, }); } else { return bodyParser.urlencoded({ limit: limit, extended: true, }); } } export function createRawMiddleware(type: RawBodyType, limit: string|number = '2500kb') { const bodyParser = require("body-parser"); if (type === RawBodyType.TYPE_BUFFER) { return bodyParser.raw({ limit: limit, type: '', }); } else { return bodyParser.text({ limit: limit, type: '', defaultCharset: 'utf-8', }); } }