[SOLVED] WebApp request raw body

I’m using Meteor 2.2, is there any way I can access the request raw body? I’m trying to work with Stripe and stuck at signature checking step.

1 Like

I have managed it this way:

import { WebApp } from 'meteor/webapp'
import bodyParser from 'body-parser'

WebApp.connectHandlers.use((req, res, next) => {
  if (req.originalUrl === '/wh/stripe') {
    // Stripe requires the raw body to construct the event
    bodyParser.raw({ type: 'application/json' })(req, res, next)
  } else {
    bodyParser.json()(req, res, next)
  }
})
2 Likes

Thank you, it works.
I found that my app uses bodyParser.json() in another place.

1 Like

In Meteor 3 you can get json from express directly and reduce a dependency:

import { WebApp } from 'meteor/webapp'

const express = WebApp.express

// Example use with GraphQL
WebApp.handlers.use(
    '/graphql', // Configure the path as you want.
    express.json(),
    expressMiddleware(server, { context }), // From `@apollo/server/express4`.
  )
1 Like

Does Apollo server v4 work well? I’m still using apollo-server-express v3.

Yes, I’m using the latest without any problems. You will need to migrate some stuff, but you can find info on that in the official docs and around here for the Meteor part. If you have issues let me know and I can copy over my setup for you to compare.

1 Like