Skip to content

Commit

Permalink
fix(doc): document way to handle unhandled requests
Browse files Browse the repository at this point in the history
  • Loading branch information
baoshan committed Sep 12, 2022
1 parent 77f40d5 commit 74f1421
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,19 @@ const webhooks = new Webhooks({
secret: "mysecret",
});

const middleware = createNodeMiddleware(webhooks, { path: "/" });

createServer(middleware).listen(3000);
const middleware = createNodeMiddleware(webhooks, { path: "/webhooks" });
createServer(async (req, res) => {
// `middleware` returns `false` when `req` is unhandled (beyond `/webhooks`)
if (await middleware(req, res)) return;
res.writeHead(404);
res.end();
}).listen(3000);
// can now receive user authorization callbacks at POST /
```

The middleware returned from `createNodeMiddleware` can also serve as an
`Express.js` middleware directly.

<table width="100%">
<tbody valign="top">
<tr>
Expand Down

0 comments on commit 74f1421

Please sign in to comment.