Skip to content

Commit a69557b

Browse files
authored
fix: Update usage example in README (#9)
* doc: Update usage example * Update README.md
1 parent f3dbcd3 commit a69557b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,26 @@ and obtain a Seam webhook secret.
8181
> This example is for [Express], see the [Svix docs for more examples in specific frameworks](https://docs.svix.com/receiving/verifying-payloads/how).
8282
8383
```js
84+
import { env } from 'node:process'
85+
8486
import { SeamWebhook } from '@seamapi/webhook'
8587
import express from 'express'
8688
import bodyParser from 'body-parser'
8789

88-
import { storeEvent } from './store-event.js'
89-
9090
const app = express()
9191

92-
const webhook = new SeamWebhook(process.env.SEAM_WEBHOOK_SECRET)
92+
const webhook = new SeamWebhook(env.SEAM_WEBHOOK_SECRET)
9393

9494
app.post(
9595
'/webhook',
9696
bodyParser.raw({ type: 'application/json' }),
9797
(req, res) => {
98-
const payload = req.body
99-
const headers = req.headers
10098
let data
101-
10299
try {
103-
data = webhook.verify(payload, headers)
100+
data = webhook.verify(req.body, req.headers)
104101
} catch {
105102
return res.status(400).send()
106103
}
107-
108104
storeEvent(data, (err) => {
109105
if (err != null) {
110106
return res.status(500).send()
@@ -113,6 +109,15 @@ app.post(
113109
})
114110
},
115111
)
112+
113+
const storeEvent = (data, callback) => {
114+
console.log(data)
115+
callback()
116+
}
117+
118+
app.listen(8080, () => {
119+
console.log('Ready to receive webhooks at http://localhost:8080/webhook')
120+
})
116121
```
117122

118123
[Express]: https://expressjs.com/

0 commit comments

Comments
 (0)