Allprod
Allprod

Reputation: 443

Cannot access Request Body in FoalTS hooks

I am trying to log request data from an API endpoint to ensure we have periodic backups for when the database crashes in between backup intervals. A logging hook has been created and attached to the controller where I access the Context variable as ctx. I have been able to access the request user through ctx.user but the body is undefined whenever I try to access it through ctx.request.body

To my knowledge vanilla JS requests have a .clone() method that clones the request because the request body is destroyed on use. My approach is to make a hook that logs the data in a file and writes to disk but so far the body showing up empty in the logging hook.

attempts to resolve:

is there anything being overlooked?

Upvotes: 1

Views: 47

Answers (1)

Loïc Poullain
Loïc Poullain

Reputation: 82

It looks like you're accessing the request body using the wrong key.

The request body is accessible through ctx.request.body and not ctx.body. 👍

Upvotes: 1

Related Questions