mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 03:55:37 +01:00
add log for detect request location
This commit is contained in:
parent
eab168eac5
commit
8b108d3aae
1 changed files with 10 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import { browserName, detectOS } from 'detect-browser';
|
||||||
import isLocalhost from 'is-localhost-ip';
|
import isLocalhost from 'is-localhost-ip';
|
||||||
import maxmind from 'maxmind';
|
import maxmind from 'maxmind';
|
||||||
import { safeDecodeURIComponent } from 'next-basics';
|
import { safeDecodeURIComponent } from 'next-basics';
|
||||||
|
import debug from 'debug';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DESKTOP_OS,
|
DESKTOP_OS,
|
||||||
|
|
@ -14,6 +15,8 @@ import {
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { NextApiRequestCollect } from 'pages/api/send';
|
import { NextApiRequestCollect } from 'pages/api/send';
|
||||||
|
|
||||||
|
const log = debug('umami:detect');
|
||||||
|
|
||||||
let lookup;
|
let lookup;
|
||||||
|
|
||||||
export function getIpAddress(req: NextApiRequestCollect) {
|
export function getIpAddress(req: NextApiRequestCollect) {
|
||||||
|
|
@ -70,11 +73,14 @@ function getRegionCode(country: string, region: string) {
|
||||||
export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
||||||
// Ignore local ips
|
// Ignore local ips
|
||||||
if (await isLocalhost(ip)) {
|
if (await isLocalhost(ip)) {
|
||||||
|
log('Localhost:', ip);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cloudflare headers
|
// Cloudflare headers
|
||||||
if (req.headers['cf-ipcountry']) {
|
if (req.headers['cf-ipcountry']) {
|
||||||
|
log('Use Cloudflare headers');
|
||||||
|
|
||||||
const country = safeDecodeURIComponent(req.headers['cf-ipcountry']);
|
const country = safeDecodeURIComponent(req.headers['cf-ipcountry']);
|
||||||
const subdivision1 = safeDecodeURIComponent(req.headers['cf-region-code']);
|
const subdivision1 = safeDecodeURIComponent(req.headers['cf-region-code']);
|
||||||
const city = safeDecodeURIComponent(req.headers['cf-ipcity']);
|
const city = safeDecodeURIComponent(req.headers['cf-ipcity']);
|
||||||
|
|
@ -88,6 +94,8 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
||||||
|
|
||||||
// Vercel headers
|
// Vercel headers
|
||||||
if (req.headers['x-vercel-ip-country']) {
|
if (req.headers['x-vercel-ip-country']) {
|
||||||
|
log('Use Vercel headers');
|
||||||
|
|
||||||
const country = safeDecodeURIComponent(req.headers['x-vercel-ip-country']);
|
const country = safeDecodeURIComponent(req.headers['x-vercel-ip-country']);
|
||||||
const subdivision1 = safeDecodeURIComponent(req.headers['x-vercel-ip-country-region']);
|
const subdivision1 = safeDecodeURIComponent(req.headers['x-vercel-ip-country-region']);
|
||||||
const city = safeDecodeURIComponent(req.headers['x-vercel-ip-city']);
|
const city = safeDecodeURIComponent(req.headers['x-vercel-ip-city']);
|
||||||
|
|
@ -121,6 +129,8 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
||||||
city,
|
city,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log('Location not found:', ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getClientInfo(req: NextApiRequestCollect) {
|
export async function getClientInfo(req: NextApiRequestCollect) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue