mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 02:58:08 +08:00
feat: 使用环境变量赋予所有本地 IP 访问权限 (#4908)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const config = require('@/config').value;
|
||||
const md5 = require('@/utils/md5');
|
||||
const isLocalhost = require('is-localhost-ip');
|
||||
|
||||
const reject = (ctx) => {
|
||||
ctx.response.status = 403;
|
||||
@@ -15,6 +16,8 @@ module.exports = async (ctx, next) => {
|
||||
|
||||
const isControlled = config.accessKey || config.whitelist || config.blacklist;
|
||||
|
||||
const allowLocalhost = config.allowLocalhost && (await isLocalhost(ip));
|
||||
|
||||
const grant = async () => {
|
||||
if (ctx.response.status !== 403) {
|
||||
await next();
|
||||
@@ -24,7 +27,7 @@ module.exports = async (ctx, next) => {
|
||||
if (requestPath === '/' || requestPath === '/robots.txt') {
|
||||
await next();
|
||||
} else {
|
||||
if (!isControlled) {
|
||||
if (!isControlled || allowLocalhost) {
|
||||
return await grant();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user