From 6064bec5b8d9f1c397996fe863165b89b89e7be3 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 21 May 2024 09:49:20 -0700 Subject: [PATCH 1/2] doc: Update usage example --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 3cb21f3..144f7fd 100644 --- a/README.md +++ b/README.md @@ -95,16 +95,12 @@ 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() From acedec2ea4f76e10cc8614879a8ce548b83aa468 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 21 May 2024 11:52:50 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 144f7fd..ddabd9a 100644 --- a/README.md +++ b/README.md @@ -81,15 +81,15 @@ 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', @@ -109,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/