Merge alpha 0.0.5 to master #54
27
src/middlewares/RawBody.ts
Normal file
27
src/middlewares/RawBody.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
|
||||||
|
const RawBodyMiddleware = (req: Request, res: Response, next: () => void) => {
|
||||||
|
const body = []
|
||||||
|
req.on('data', chunk => {
|
||||||
|
body.push(chunk)
|
||||||
|
})
|
||||||
|
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', () => {
|
||||||
|
res.sendStatus(400)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RawBodyMiddleware
|
Loading…
x
Reference in New Issue
Block a user