expressAdapter
expressAdapter<
TEventMap>(router,options): (req,res,next) =>Promise<void>
Defined in: express/src/index.ts:41
Creates an Express middleware for handling webhooks
IMPORTANT: This adapter requires req.body to be a raw Buffer or string.
Use express.raw({ type: 'application/json' }) middleware on your webhook route.
Type Parameters
Section titled “Type Parameters”TEventMap
Section titled “TEventMap”TEventMap extends Record<string, WebhookEvent>
Parameters
Section titled “Parameters”router
Section titled “router”WebhookRouter<TEventMap>
The WebhookRouter instance
options
Section titled “options”ExpressAdapterOptions<TEventMap[keyof TEventMap]>
Adapter options including a verifier function
Returns
Section titled “Returns”Express middleware function
(
req,res,next):Promise<void>
Parameters
Section titled “Parameters”Request
Response
NextFunction
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”import express from 'express';import { expressAdapter } from '@kotodayori/express';import { createStripeVerifier, StripeWebhookRouter } from '@kotodayori/stripe';
const router = new StripeWebhookRouter();const app = express();
app.post('/webhook', express.raw({ type: 'application/json' }), expressAdapter(router, { verifier: createStripeVerifier(stripe, 'whsec_...'), }));