Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes the onUnhandledRequest middleware option #740

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
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
41 changes: 11 additions & 30 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);
// can now receive user authorization callbacks at POST /
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 /webhooks
```

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

<table width="100%">
<tbody valign="top">
<tr>
Expand Down Expand Up @@ -597,32 +604,6 @@ createServer(middleware).listen(3000);

Used for internal logging. Defaults to [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console) with `debug` and `info` doing nothing.

</td>
</tr>
<tr>
<td>
<code>onUnhandledRequest</code>
<em>
function
</em>
</td>
<td>

Defaults to

```js
function onUnhandledRequest(request, response) {
response.writeHead(400, {
"content-type": "application/json",
});
response.end(
JSON.stringify({
error: error.message,
})
);
}
```

</td>
</tr>
<tbody>
Expand Down
Loading