#JDesignV2-webhooks

1 messages · Page 1 of 1 (latest)

sterile light
#

const raw = Buffer.from(JSON.stringify(req.body) is definitely not going to work, since that call to stringify will modify the incoming request body

flint shell
#

Yes... I already tried that...

flint shell
#

not the best ^^

#

The weird thing now is when I implement app.use((req, res, next) => { if (req.originalUrl === '/webhook') { next(); } else { express.json()(req, res, next); } }); this for example... my Server doesn't even get to the constructEvent method...

sterile light
#

it has to match exactly including the whitespace(that is part of the raw string we send)

flint shell
#

hmmm ok i will try...

sterile light
#

also make sure you're actually using the right secret

#

i.e. log it out and compare it to the whsec_xxx emitted when running stripe listen if that's how you're forwarding the event, or to the secret on the dashboard page for the endpoint you created

flint shell
#

Hmmm... to the right is the request.body and on the left the original...

#

It just 'over-jumps' the req.on() Methods completely...

#

The weird thing now is that the Server gets stuck in this Method (above)

#

It does not even 'reach' this part anymore...

sterile light
#

ok on the right that is wrong

#

you can see it has [Object] for example

#

that means what you are looking at has already been parsed into a JS object by middleware in Express

flint shell
#

hmmm... ok i thaught that is only because of the consol.log in the terminal...

sterile light
#

well if you log an object it will look that way yes

#

the problem is you have an object. You should have a string

flint shell
#

hmmm ok

#

but why 😅

#

I did not parsed it before printing it out...

sterile light
sterile light
flint shell
sterile light
#

Express sees that an incoming request is JSON so it helpfully converts it to a JS object, but you want to avoid that happening here

flint shell
#

hmmm ok

#

I tried it now but the output I get seems to be exactly the same as before...

#

Also with [Object]

#

This is my implementation now ...

sterile light
#

can you share the full code you have?(in text not a screenshot)

#

can you do express.raw({type: 'application/json'}) like in the example?

flint shell
#

yes one sec.

#

same result... 😦

#

app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {...});

#

Does it maybe has something todo with Google Cloud App Engine?

sterile light
#

possibly, but I have no experience with that platform. Seems unlikely

#

are you 100% sure you're actually running that code, i.e. the file is definitely saved and 'deployed' ? It should just work as far as I can tell

flint shell
#

I am only currently trying it out with the Stripe CLI... I am always restarting the node Server with npm start... Is there another way? Like f.ex. a 'hard reload' or smth?

#

WTF ok wait

#

no way

#

I have these lines of code inside my server.js... from one of your tutorials to create a checkout session for a subsrciption... when I comment them out it. works... 🤯
is it the app.use(express.json()) that killed the 'getting the raw body'?

#

it works now lol ^^

sterile light
#

ah yeah

#

for some reason that overrides the route config which seems backwards but oh well! glad you got it working!

flint shell
#

I feel so dump right now hahaha

#

But thanks for the support!

sterile light
#

happy to help!