mirror of
https://github.com/umami-software/umami.git
synced 2026-02-18 19:45:35 +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 maxmind from 'maxmind';
|
||||
import { safeDecodeURIComponent } from 'next-basics';
|
||||
import debug from 'debug';
|
||||
|
||||
import {
|
||||
DESKTOP_OS,
|
||||
|
|
@ -14,6 +15,8 @@ import {
|
|||
} from './constants';
|
||||
import { NextApiRequestCollect } from 'pages/api/send';
|
||||
|
||||
const log = debug('umami:detect');
|
||||
|
||||
let lookup;
|
||||
|
||||
export function getIpAddress(req: NextApiRequestCollect) {
|
||||
|
|
@ -70,11 +73,14 @@ function getRegionCode(country: string, region: string) {
|
|||
export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
||||
// Ignore local ips
|
||||
if (await isLocalhost(ip)) {
|
||||
log('Localhost:', ip);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cloudflare headers
|
||||
if (req.headers['cf-ipcountry']) {
|
||||
log('Use Cloudflare headers');
|
||||
|
||||
const country = safeDecodeURIComponent(req.headers['cf-ipcountry']);
|
||||
const subdivision1 = safeDecodeURIComponent(req.headers['cf-region-code']);
|
||||
const city = safeDecodeURIComponent(req.headers['cf-ipcity']);
|
||||
|
|
@ -88,6 +94,8 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
|||
|
||||
// Vercel headers
|
||||
if (req.headers['x-vercel-ip-country']) {
|
||||
log('Use Vercel headers');
|
||||
|
||||
const country = safeDecodeURIComponent(req.headers['x-vercel-ip-country']);
|
||||
const subdivision1 = safeDecodeURIComponent(req.headers['x-vercel-ip-country-region']);
|
||||
const city = safeDecodeURIComponent(req.headers['x-vercel-ip-city']);
|
||||
|
|
@ -121,6 +129,8 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
|||
city,
|
||||
};
|
||||
}
|
||||
|
||||
log('Location not found:', ip);
|
||||
}
|
||||
|
||||
export async function getClientInfo(req: NextApiRequestCollect) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue