From 5e86d7ab9c5200d794c3adb2b422d20a2aefd2ce Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 13 Aug 2022 02:00:50 +0200 Subject: restructure to single project --- api/src/middlewares/BodyParser.ts | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 api/src/middlewares/BodyParser.ts (limited to 'api/src/middlewares/BodyParser.ts') diff --git a/api/src/middlewares/BodyParser.ts b/api/src/middlewares/BodyParser.ts deleted file mode 100644 index 35db3c6f..00000000 --- a/api/src/middlewares/BodyParser.ts +++ /dev/null @@ -1,19 +0,0 @@ -import bodyParser, { OptionsJson } from "body-parser"; -import { NextFunction, Request, Response } from "express"; -import { HTTPError } from "@fosscord/util"; - -export function BodyParser(opts?: OptionsJson) { - const jsonParser = bodyParser.json(opts); - - return (req: Request, res: Response, next: NextFunction) => { - if (!req.headers["content-type"]) req.headers["content-type"] = "application/json"; - - jsonParser(req, res, (err) => { - if (err) { - // TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...) - return next(new HTTPError("Invalid Body", 400)); - } - next(); - }); - }; -} -- cgit 1.5.1