From a88c0389c1dc6862fe1a10b03c1345a1196869c5 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 20 Dec 2020 19:08:02 +0100 Subject: [PATCH] Code + Comment cleanup for the middlewares ref #39 --- src/middlewares/ErrorHandler.ts | 2 +- src/middlewares/RawBody.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/middlewares/ErrorHandler.ts b/src/middlewares/ErrorHandler.ts index 40c1ff6..71ef2db 100644 --- a/src/middlewares/ErrorHandler.ts +++ b/src/middlewares/ErrorHandler.ts @@ -1,7 +1,7 @@ import { ExpressErrorMiddlewareInterface, Middleware } from "routing-controllers"; /** - * Our Error handling middlware that returns our custom httperrors to the user + * Our Error handling middlware that returns our custom httperrors to the user. */ @Middleware({ type: "after" }) export class ErrorHandler implements ExpressErrorMiddlewareInterface { diff --git a/src/middlewares/RawBody.ts b/src/middlewares/RawBody.ts index 58ff67d..57efefa 100644 --- a/src/middlewares/RawBody.ts +++ b/src/middlewares/RawBody.ts @@ -1,5 +1,10 @@ import { Request, Response } from 'express'; +/** + * Custom express middleware that appends the raw body to the request obeject. + * Mainly used for parsing csvs from boddies. + */ + const RawBodyMiddleware = (req: Request, res: Response, next: () => void) => { const body = [] req.on('data', chunk => { @@ -8,15 +13,6 @@ const RawBodyMiddleware = (req: Request, res: Response, next: () => void) => { req.on('end', () => { const rawBody = Buffer.concat(body) req['rawBody'] = rawBody - /* - switch (req.header('content-type')) { - case 'application/json': - req.body = JSON.parse(rawBody.toString()) - break - // add more body parsing if needs be - default: - } - */ next() }) req.on('error', () => {