mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 18:48:12 +08:00
33 lines
807 B
JavaScript
33 lines
807 B
JavaScript
const config = require('@/config').value;
|
|
|
|
const reject = (ctx) => {
|
|
ctx.response.status = 403;
|
|
|
|
throw Error('Access denied.');
|
|
};
|
|
|
|
module.exports = async (ctx, next) => {
|
|
const ip = ctx.ips[0] || ctx.ip;
|
|
const requestPath = ctx.request.path;
|
|
|
|
if (requestPath === '/') {
|
|
await next();
|
|
} else {
|
|
if (config.whitelist) {
|
|
if (!(config.whitelist.includes(ip) || config.whitelist.includes(requestPath))) {
|
|
reject(ctx);
|
|
}
|
|
} else {
|
|
if (config.blacklist) {
|
|
if (config.blacklist.includes(ip) || config.blacklist.includes(requestPath)) {
|
|
reject(ctx);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ctx.response.status !== 403) {
|
|
await next();
|
|
}
|
|
}
|
|
};
|