Skip to content

Unable to get raw request body #6794

@jonpalmisc

Description

@jonpalmisc

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

  1. Create a config/env/**/request.json with the following content:
{
  "parser": {
    "enabled": true,
    "multipart": true,
    "includeUnparsed": true
  }
}
  1. Import the unparsed symbol helper from koa-body
const unparsed = require('koa-body/unparsed.js'); 
  1. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions