mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 04:25:03 +02:00
24 lines
578 B
TypeScript
24 lines
578 B
TypeScript
import type { Request } from 'express'
|
|
|
|
export function retrieveJson (req: Request): Promise<any> {
|
|
const body: Uint8Array[] = []
|
|
return new Promise((resolve, reject) => {
|
|
req
|
|
.on('data', (chunk: Uint8Array) => {
|
|
body.push(chunk)
|
|
})
|
|
.on('error', (err) => {
|
|
reject(err)
|
|
})
|
|
.on('end', () => {
|
|
// on end of data, perform necessary action
|
|
try {
|
|
const data = JSON.parse(Buffer.concat(body).toString())
|
|
resolve(data)
|
|
} catch (err: any) {
|
|
reject(err)
|
|
}
|
|
})
|
|
})
|
|
}
|