mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 14:07:54 +08:00
test: blacklist in middleware/access-control
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const art = require('art-template');
|
||||
const path = require('path');
|
||||
const blacklist = process.env.BLACKLIST && process.env.BLACKLIST.split(',');
|
||||
const whitelist = process.env.WHITELIST && process.env.WHITELIST.split(',');
|
||||
const config = require('../config');
|
||||
|
||||
const reject = (ctx) => {
|
||||
ctx.response.status = 403;
|
||||
@@ -21,13 +20,13 @@ module.exports = async (ctx, next) => {
|
||||
if (requestPath === '/') {
|
||||
await next();
|
||||
} else {
|
||||
if (whitelist) {
|
||||
if (!(whitelist.indexOf(ip) !== -1 || whitelist.indexOf(requestPath) !== -1)) {
|
||||
if (config.whitelist) {
|
||||
if (!(config.whitelist.indexOf(ip) !== -1 || config.whitelist.indexOf(requestPath) !== -1)) {
|
||||
reject(ctx);
|
||||
}
|
||||
} else {
|
||||
if (blacklist) {
|
||||
if (blacklist.indexOf(ip) !== -1 || blacklist.indexOf(requestPath) !== -1) {
|
||||
if (config.blacklist) {
|
||||
if (config.blacklist.indexOf(ip) !== -1 || config.blacklist.indexOf(requestPath) !== -1) {
|
||||
reject(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user