From dba68e67fb2f5f54ecbbeaf1d7efbd427af622e6 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Mon, 8 Oct 2018 18:21:22 +0100 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=BB=91=E7=99=BD=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E9=80=BB=E8=BE=91=20(#844)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #840 可能没这么快 merge, 剥离这部分出来 --- middleware/access-control.js | 22 ++++++++++++++-------- routes/bbc/index.js | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/middleware/access-control.js b/middleware/access-control.js index 412ebc347..9cae1ce55 100644 --- a/middleware/access-control.js +++ b/middleware/access-control.js @@ -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(); }; diff --git a/routes/bbc/index.js b/routes/bbc/index.js index b948d0556..59e7d0b7f 100644 --- a/routes/bbc/index.js +++ b/routes/bbc/index.js @@ -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 {