Hello! I need to send to my NestJS server a stream.
Request to my server:
const req = request(
`${appService}/process-payments`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
},
(res) => {
console.log(`STATUS: ${res.statusCode}`);
res.on('data', (chunk) => {
console.log(`Body: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.');
});
}
);
stream.pipe(req);
// then in a loop I do the following:
stream.write(data + '\n');
// after the loop
stream.end();
my controller method:
@Post('process-payments')
async processPayments(@Req() stream: Readable): Promise<void> {
console.log('here.');
stream.on('data', (data) => {
console.log(data);
});
}
and I got:
Body: {"message":"Unexpected token { in JSON at position 32","error":"Bad Request","statusCode":400}
I also tried to disable bodyParser or use rawBody, but I have not succeeded.