-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Description
Describe the bug
I am trying to obtain the raw request body to I can verify it using Stripe's library. This question was previously asked #4720, but the solution the user posted no longer seems to work.
Steps to reproduce the behavior
- Create a
config/env/**/request.jsonwith the following content:
{
"parser": {
"enabled": true,
"multipart": true,
"includeUnparsed": true
}
}- Import the
unparsedsymbol helper fromkoa-body
const unparsed = require('koa-body/unparsed.js'); - Attempt to access the unparsed body.
async index(ctx) {
const unparsedBody = ctx.request.body[unparsed];
console.log(unparsedBody) // undefined
}Expected behavior
I would have received the unparsed body.
Screenshots
N/A
Code snippets
config/env/development/request.json
{
"parser": {
"enabled": true,
"multipart": true,
"includeUnparsed": true
}
}api/test/controllers/test.js
"use strict";
const unparsed = require("koa-body/unparsed.js");
module.exports = {
async test(ctx) {
console.log("\n==== Environment =======================");
console.log(`NODE_ENV=${process.env.NODE_ENV}`);
console.log("\n==== Requests Config ===================");
console.log(strapi.config.request);
console.log("\n==== Unparsed Symbol ===================");
console.log(unparsed);
console.log("\n==== Unparsed Body =====================");
console.log(ctx.request.body[unparsed]);
console.log("");
return {};
},
};Output:
==== Environment =======================
NODE_ENV=development
==== Requests Config ===================
{ parser: { enabled: true, multipart: true, includeUnparsed: true } }
==== Unparsed Symbol ===================
Symbol(unparsedBody)
==== Unparsed Body =====================
undefined
System
- Node.js version: 12.16.1
- NPM version: 6.13.4 (Yarn 1.22.4)
- Strapi version: 3.0.1
- Database: PostgreSQL
- Operating system: macOS 10.15.5
Metadata
Metadata
Assignees
Labels
No labels