Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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/
Expand Down