parent
43a4f1118d
commit
a88c0389c1
@ -1,7 +1,7 @@
|
|||||||
import { ExpressErrorMiddlewareInterface, Middleware } from "routing-controllers";
|
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" })
|
@Middleware({ type: "after" })
|
||||||
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
|
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
import { Request, Response } from 'express';
|
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 RawBodyMiddleware = (req: Request, res: Response, next: () => void) => {
|
||||||
const body = []
|
const body = []
|
||||||
req.on('data', chunk => {
|
req.on('data', chunk => {
|
||||||
@ -8,15 +13,6 @@ const RawBodyMiddleware = (req: Request, res: Response, next: () => void) => {
|
|||||||
req.on('end', () => {
|
req.on('end', () => {
|
||||||
const rawBody = Buffer.concat(body)
|
const rawBody = Buffer.concat(body)
|
||||||
req['rawBody'] = rawBody
|
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()
|
next()
|
||||||
})
|
})
|
||||||
req.on('error', () => {
|
req.on('error', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user