Introduce `.notFound()` handler
Problem
In production, any application pointing to the public is bound to receive bot requests. Pictured above are bots attacking our non-existent WordPress site. We want to handle these requests so they do not trigger an error with Sentry.
While we can handle any request that is not /slack, we worry about when the bot discovers the /slack path. How will we ensure this does not cause additional noise in our application?
Proposal
Introduce a .notFound() handler for requests that don't resolve to any existing endpoint. Inspired by hono's notFound() handler https://hono.dev/docs/api/hono#not-found
The handler is triggered when no matching request is met.
Looking forward to your thoughts or if there is a better recommendation on how to handle 404s
Hi @zhawtof, thanks for the suggestion. slack-edge is not a general web app framework, so I'd like to hold off adding the feature Hono provides. Instead, I'd suggest a simple solution like this:
const response = await app.run(request);
if (response.status == 404) {
return new Response("Not Found", { status: 200 });
}
return response;
Hope this works for you.
Ya, that works for us. Thanks Kaz.
This is off-topic, but I was thinking the other day that slack-edge would be a very interesting adapter for Hono in the future. The middleware and context share a lot of the same underlying principles.
Yeah, that's an interesting area to explore. When a Hono user wants to add slack-edge endpoints as part of a larger Hono web application, a seamless integration/adapter for Hono would be beneficial.
Regarding the similarity, it's not surprising! The early version of bolt-js (then called "slapp") was highly inspired by Express.js, and slack-edge follows bolt-js.