-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exclude): regroup all exclusion logic
Also add a filter function to exclude custom request
- Loading branch information
1 parent
05ae452
commit 3184b20
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |