feat: 使用环境变量赋予所有本地 IP 访问权限 (#4908)

This commit is contained in:
Henry Wang
2020-06-07 15:45:54 +01:00
committed by GitHub
parent 46f67b833d
commit 731a5d43f7
6 changed files with 13 additions and 3 deletions

View File

@@ -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();
}