From 6a4bfd21f632c8289729c7945d57a7281a0e2f55 Mon Sep 17 00:00:00 2001 From: Ethan Zimbelman Date: Mon, 16 Oct 2023 14:19:25 -0700 Subject: [PATCH] include a middleware example with express receiver --- docs/_advanced/custom_routes.md | 8 +++++++- docs/_advanced/ja_custom_routes.md | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/_advanced/custom_routes.md b/docs/_advanced/custom_routes.md index 1d501646c..28c47b057 100644 --- a/docs/_advanced/custom_routes.md +++ b/docs/_advanced/custom_routes.md @@ -57,7 +57,7 @@ const app = new App({
-Adding custom HTTP routes is quite straightforward when using Bolt’s built-in ExpressReceiver. Since `v2.1.0`, `ExpressReceiver` added a `router` property, which exposes the Express [Router](http://expressjs.com/en/4x/api.html#router) on which additional routes can be added. +Adding custom HTTP routes is quite straightforward when using Bolt’s built-in ExpressReceiver. Since `v2.1.0`, `ExpressReceiver` added a `router` property, which exposes the Express [Router](http://expressjs.com/en/4x/api.html#router) on which additional routes and middleware can be added.
```javascript @@ -78,6 +78,12 @@ app.event('message', async ({ event, client }) => { await client.chat.postMessage(...); }); +// Middleware methods execute on every web request +receiver.router.use((req, res, next) => { + console.log(`Request time: ${Date.now()}`); + next(); +}); + // Other web requests are methods on receiver.router receiver.router.post('/secret-page', (req, res) => { // You're working with an express req and res now. diff --git a/docs/_advanced/ja_custom_routes.md b/docs/_advanced/ja_custom_routes.md index e427080da..837dac248 100644 --- a/docs/_advanced/ja_custom_routes.md +++ b/docs/_advanced/ja_custom_routes.md @@ -78,6 +78,11 @@ app.event('message', async ({ event, client }) => { await client.chat.postMessage(...); }); +receiver.router.use((req, res, next) => { + console.log(`Request time: ${Date.now()}`); + next(); +}); + // それ以外の Web リクエストの処理は receiver.router のメソッドで定義 receiver.router.post('/secret-page', (req, res) => { // ここでは Express のリクエストやレスポンスをそのまま扱う @@ -86,7 +91,7 @@ receiver.router.post('/secret-page', (req, res) => { (async () => { await app.start(); - console.log('⚡️ Bolt app started''); + console.log('⚡️ Bolt app started'); })(); ```