diff --git a/README.md b/README.md index 3cb21f3..ddabd9a 100644 --- a/README.md +++ b/README.md @@ -81,30 +81,26 @@ and obtain a Seam webhook secret. > This example is for [Express], see the [Svix docs for more examples in specific frameworks](https://docs.svix.com/receiving/verifying-payloads/how). ```js +import { env } from 'node:process' + import { SeamWebhook } from '@seamapi/webhook' import express from 'express' import bodyParser from 'body-parser' -import { storeEvent } from './store-event.js' - const app = express() -const webhook = new SeamWebhook(process.env.SEAM_WEBHOOK_SECRET) +const webhook = new SeamWebhook(env.SEAM_WEBHOOK_SECRET) app.post( '/webhook', bodyParser.raw({ type: 'application/json' }), (req, res) => { - const payload = req.body - const headers = req.headers let data - try { - data = webhook.verify(payload, headers) + data = webhook.verify(req.body, req.headers) } catch { return res.status(400).send() } - storeEvent(data, (err) => { if (err != null) { return res.status(500).send() @@ -113,6 +109,15 @@ app.post( }) }, ) + +const storeEvent = (data, callback) => { + console.log(data) + callback() +} + +app.listen(8080, () => { + console.log('Ready to receive webhooks at http://localhost:8080/webhook') +}) ``` [Express]: https://expressjs.com/