blacklist tests

This commit is contained in:
Lloyd Brookes
2015-11-13 19:55:52 +00:00
parent 15e0074770
commit fc2548e40e
4 changed files with 61 additions and 26 deletions

View File

@ -21,7 +21,8 @@ function getApp (options) {
static: {},
serveIndex: {},
log: {},
compress: false
compress: false,
blacklist: []
}, options)
const log = options.log
@ -33,13 +34,15 @@ function getApp (options) {
app.use(convert(cors()))
/* path blacklist */
app.use(function pathBlacklist (ctx, next) {
if (/css$/.test(ctx.path)) {
ctx.throw(403, 'FUCK NO.')
} else {
return next()
}
})
if (options.blacklist.length) {
app.use(function pathBlacklist (ctx, next) {
if (options.blacklist.some(regexp => regexp.test(ctx.path))) {
ctx.throw(403, 'Blacklisted')
} else {
return next()
}
})
}
app.use(convert(conditional()))
app.use(convert(etag()))