修复黑白名单逻辑 (#844)

#840 可能没这么快 merge, 剥离这部分出来
This commit is contained in:
Henry Wang
2018-10-09 01:21:22 +08:00
committed by DIYgod
parent 8b9060bec0
commit dba68e67fb
2 changed files with 15 additions and 9 deletions
+14 -8
View File
@@ -18,17 +18,23 @@ module.exports = async (ctx, next) => {
const ip = ctx.ips[0] || ctx.ip;
const requestPath = ctx.request.path;
if (whitelist) {
if (!(whitelist.indexOf(ip) !== -1 || whitelist.indexOf(requestPath) !== -1)) {
reject(ctx);
}
if (requestPath === '/') {
await next();
} else {
if (blacklist) {
if (blacklist.indexOf(ip) !== -1 || blacklist.indexOf(requestPath) !== -1) {
if (whitelist) {
if (!(whitelist.indexOf(ip) !== -1 || whitelist.indexOf(requestPath) !== -1)) {
reject(ctx);
}
} else {
if (blacklist) {
if (blacklist.indexOf(ip) !== -1 || blacklist.indexOf(requestPath) !== -1) {
reject(ctx);
}
}
}
if (ctx.response.status !== 403) {
await next();
}
}
await next();
};
+1 -1
View File
@@ -12,7 +12,7 @@ module.exports = async (ctx) => {
channel = channel.split('-').join('/');
if (channel === 'chinese') {
feed = await parser.parseURL('https//feeds.bbci.co.uk/zhongwen/simp/rss.xml');
feed = await parser.parseURL('https://feeds.bbci.co.uk/zhongwen/simp/rss.xml');
title = 'BBC News 中文网';
link = 'https://www.bbc.com/zhongwen/simp';
} else {