Skip to content

Commit 2807570

Browse files
committed
docs(webhooks): clarify Node and Bun quickstart
1 parent fbafedf commit 2807570

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

webhooks/quickstart.mdx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ creation or rotation. `signingSecret` exists for consumers of the legacy
5353

5454
The following Hono handler verifies any of the space-delimited signatures sent
5555
during key rotation. It signs the exact request bytes before parsing JSON.
56+
Implement the imported `enqueue(event, id)` function with your durable queue.
57+
Use `id` as a unique key so retries do not repeat non-idempotent work.
5658

57-
```ts server.ts
59+
```ts webhook.ts
5860
import { createHmac, timingSafeEqual } from "node:crypto";
5961
import { Hono } from "hono";
62+
import { enqueue } from "./queue";
6063

61-
const app = new Hono();
64+
export const app = new Hono();
6265
const secret = process.env.SPECTRUM_WEBHOOK_SECRET!;
6366
const toleranceSeconds = 5 * 60;
6467

@@ -103,15 +106,36 @@ app.post("/spectrum-webhook", async (c) => {
103106
await enqueue(event, id);
104107
return c.text("ok", 200);
105108
});
106-
107-
export default { port: 3000, fetch: app.fetch };
108109
```
109110

110-
```sh
111-
export SPECTRUM_WEBHOOK_SECRET='whsec_YWJj...'
112-
bun add hono
113-
bun server.ts
114-
```
111+
<Tabs>
112+
<Tab title="Bun">
113+
```ts server.bun.ts
114+
import { app } from "./webhook";
115+
116+
export default { port: 3000, fetch: app.fetch };
117+
```
118+
119+
```sh
120+
bun add hono
121+
SPECTRUM_WEBHOOK_SECRET='whsec_YWJj...' bun server.bun.ts
122+
```
123+
</Tab>
124+
<Tab title="Node.js">
125+
```ts server.node.ts
126+
import { serve } from "@hono/node-server";
127+
import { app } from "./webhook";
128+
129+
serve({ port: 3000, fetch: app.fetch });
130+
```
131+
132+
```sh
133+
npm install hono @hono/node-server
134+
npm install --save-dev tsx
135+
SPECTRUM_WEBHOOK_SECRET='whsec_YWJj...' npx tsx server.node.ts
136+
```
137+
</Tab>
138+
</Tabs>
115139

116140
<Warning>
117141
Do not call `json()` before verification. Parsing and reserializing the body can

0 commit comments

Comments
 (0)