[Server] allow addition of middleware BEFORE default middlewares (for Stripe Webhook Verification) #1086
Replies: 2 comments 2 replies
-
Looks like this can be solved in this way: Recommend closing the issue |
Beta Was this translation helpful? Give feedback.
-
As @santolucito mentions, this is solved (as is being done in the Open SaaS stripe webhook) by first deleting the default config, then adding the desired one, like this: export const stripeMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
middlewareConfig.delete('express.json');
middlewareConfig.set('express.raw', express.raw({ type: 'application/json' }));
return middlewareConfig;
}; But would it make more sense that when consuming a user's MiddlewareConfigFn we just inject it at the top of the middleware stack, since express executes middleware functions in the order they are applied? This way, the user has to know less about Wasp's default middleware config. Or would having the 'express.json' function still exist within the middleware execution cause issues? |
Beta Was this translation helpful? Give feedback.
-
At the moment, when trying to verifying the signatures sent by stripe in the request headers, its not possible because
express.json
mutates the request. Stripe needs the raw request body in order to verify signatures. This can be accomplished like so:but the raw request must come through first, before being parsed by the JSON middleware: https://stripe.com/docs/webhooks/signatures
Beta Was this translation helpful? Give feedback.
All reactions