After setting up a NestJs controller and a facade service for handling POST requests, I encountered an issue where the functionality only worked for content-type "text/plain" and not for "application/json", even though the body of the request was identical.
Below is the code snippet from the controller:
@Public()
@Post(SERVER_COVID_A_CASA_CARE_PLAN_NOTIFICATION_PATH)
getNotification(@Req() request: Request, @Res() response: Response) {
this.facade.manageCarePlanNotification(request, response);
}
And here is the method in the facade service:
manageCarePlanNotification(request: Request, response: Response) {
let jsonBodyReq = '';
request.on('data', function (data) {
jsonBodyReq += data;
});
request.on('end', () => {
this.manageCarePlanNotificationRequest(jsonBodyReq, response);
});
request.on('error', function (e) {
console.log(e.message);
});
}
While the JSON request successfully reaches the controller and the manageCarePlanNotification method, it does not trigger the 'data' event as expected, unlike the text/plain request. This behavior persists in the 'end' event as well.
If anyone has any insights or suggestions on how to address this issue, it would be greatly appreciated! :)