Added IP address ignore list.

This commit is contained in:
Mike Cao 2020-10-03 19:07:56 -07:00
parent 34098bd0b4
commit fc22f5969c
2 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "umami", "name": "umami",
"version": "0.74.0", "version": "0.75.0",
"description": "A simple, fast, website analytics alternative to Google Analytics. ", "description": "A simple, fast, website analytics alternative to Google Analytics. ",
"author": "Mike Cao <mike@mikecao.com>", "author": "Mike Cao <mike@mikecao.com>",
"license": "MIT", "license": "MIT",

View File

@ -3,12 +3,22 @@ import { savePageView, saveEvent } from 'lib/queries';
import { useCors, useSession } from 'lib/middleware'; import { useCors, useSession } from 'lib/middleware';
import { ok, badRequest } from 'lib/response'; import { ok, badRequest } from 'lib/response';
import { createToken } from 'lib/crypto'; import { createToken } from 'lib/crypto';
import { getIpAddress } from '../../lib/request';
export default async (req, res) => { export default async (req, res) => {
if (isBot(req.headers['user-agent'])) { if (isBot(req.headers['user-agent'])) {
return ok(res); return ok(res);
} }
if (process.env.IGNORE_IP) {
const ips = process.env.IGNORE_IP.split(',').map(n => n.trim());
const ip = getIpAddress(req);
if (ips.includes(ip)) {
return ok(res);
}
}
await useCors(req, res); await useCors(req, res);
await useSession(req, res); await useSession(req, res);