feat(plugins): add req.rawBody for routes

Stripe webhooks endpoints requires to read the raw request body.
https://docs.stripe.com/webhooks#verify-webhook-signatures-with-official-libraries
This commit is contained in:
kontrollanten
2024-03-29 08:22:26 +01:00
committed by Chocobozzz
parent 107e6e73a6
commit 1b323f4f65
5 changed files with 37 additions and 1 deletions

View File

@@ -9,6 +9,10 @@ async function register ({
router.post('/form/post/mirror', (req, res) => {
res.json(req.body)
})
router.post('/form/post/mirror-raw-body', (req, res) => {
res.json(JSON.parse(req.rawBody))
})
}
async function unregister () {

View File

@@ -80,6 +80,24 @@ describe('Test plugin helpers', function () {
}
})
it('Should mirror the raw post body', async function () {
const body = {
torso: 'arms',
legs: 'feet'
}
for (const path of basePaths) {
const res = await makePostBodyRequest({
url: server.url,
path: path + 'form/post/mirror-raw-body',
fields: body,
expectedStatus: HttpStatusCode.OK_200
})
expect(res.body).to.deep.equal(body)
}
})
it('Should remove the plugin and remove the routes', async function () {
await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' })