-
Hi everyone, I'm working on a project using Hono and I need to apply middleware only to GET routes. Normally, I would use app.use to apply middleware globally, but this middleware should only affect GET requests. To achieve this, I used app.get instead of app.use for the middleware. Here’s a simplified version of my code: import amazon from './routes/amazon.js'
import apiKeys from './routes/apiKeys.js'
const app = new Hono()
app.get('/*', apiKeyAuth({
enforceAuth: true
}))
app.route('/', amazon)
app.route('/', apiKeys) In this code, apiKeyAuth middleware is applied only to GET routes. My question is: Is this an acceptable and recommended approach to limit middleware to GET routes in Hono? Are there any potential issues or better practices I should be aware of? Any advice or suggestions would be greatly appreciated. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That sounds like the recommended way, also described in the docs, so I that makes perfect sense! |
Beta Was this translation helpful? Give feedback.
That sounds like the recommended way, also described in the docs, so I that makes perfect sense!