Skip to content

Commit

Permalink
feat(exclude): regroup all exclusion logic
Browse files Browse the repository at this point in the history
Also add a filter function to exclude custom request
  • Loading branch information
stephanebachelier committed Apr 5, 2016
1 parent 05ae452 commit 3184b20
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/exclude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

export default function exclude (req, service, exclusions = {}) {
if (service) {
if (service.use && service.use.cache === false) {
return true
}
}

if ((typeof exclusions.filter === 'function') && !exclusions.filter(req)) {
return true
}

// do not cache request with query
if (exclusions.query && req.url.match(/\?.*$/)) {
return true
}

let found = false
const paths = exclusions.paths || []

paths.forEach(regexp => {
if (req.url.match(regexp)) {
found = true
return found
}
})

if (found) {
return true
}

// All rules explained. fo not rewrite regexp.
return false
}

0 comments on commit 3184b20

Please sign in to comment.