Skip to content

Commit

Permalink
fix(app): only apply cache rules ro routes (not middleware)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 18, 2022
1 parent e9285da commit 4603279
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,17 @@ function createNitroApp (): NitroApp {

for (const h of handlers) {
let handler = h.lazy ? lazyEventHandler(h.handler) : h.handler

// Wrap matching handlers for caching route options
const routeRules = getRouteRulesForPath(h.route.replace(/:\w+|\*\*/g, '_'))
if (routeRules.cache) {
handler = cachedEventHandler(handler, {
group: 'nitro/routes',
...routeRules.cache
})
}

if (h.middleware || !h.route) {
const middlewareBase = (config.app.baseURL + (h.route || '/')).replace(/\/+/g, '/')
h3App.use(middlewareBase, handler)
} else {
const routeRules = getRouteRulesForPath(h.route.replace(/:\w+|\*\*/g, '_'))
if (routeRules.cache) {
handler = cachedEventHandler(handler, {
group: 'nitro/routes',
...routeRules.cache
})
}
router.use(h.route, handler, h.method)
}
}
Expand Down

0 comments on commit 4603279

Please sign in to comment.