url-whitelist can create whitelists by including and excluding url patterns and check urls against them
see url-pattern for supported url patterns
npm install url-whitelist
newWhitelist = require 'url-whitelist'
whitelist = newWhitelist
whitelistcheck '/users/1' # => truewhitelistcheck '/projects/1' # => false
by default a whitelist excludes everything. you can include everything by default and then selectively exclude patterns.
blacklist = newWhitelistblacklistinclude '*'blacklistexclude '/users/:id'blacklistcheck 'sajdflkasjdfl' # => trueblacklistcheck '/users/:id' # => falseblacklistcheck 'skljdf' # => true
/projects/* except for
newWhitelist = require 'url-whitelist'whitelist = newWhitelistwhitelistinclude '/projects/*'whitelistexclude '/projects/hidden/*'whitelistexclude '/projects/:id/secret'whitelistinclude '/users/:id'whitelistcheck '/projects/foo/bar/baz' # => truewhitelistcheck '/projects/hidden/bar/baz' # => falsewhitelistcheck '/projects/5/secret' # => falsewhitelistcheck '/projects/5/secret/foo' # => truewhitelistcheck '/users' # => falsewhitelistcheck '/users/5' # => truewhitelistcheck '/tasks/57' # => false
whitelisted = falsego through all include- and exclude-patterns in the order they were defined:if url matches patternif is includewhitelisted = trueelsewhitelisted = false