Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow send custom location from server #3153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iMuFeng
Copy link

@iMuFeng iMuFeng commented Jan 4, 2025

No description provided.

Copy link

vercel bot commented Jan 4, 2025

@iMuFeng is attempting to deploy a commit to the umami-software Team on Vercel.

A member of the Team first needs to authorize it.

@mikecao
Copy link
Collaborator

mikecao commented Jan 10, 2025

Other than Vercel and Cloudflare, are there other providers that offer headers?

@iMuFeng
Copy link
Author

iMuFeng commented Jan 11, 2025

Scenario: We have two services - an API server and a Umami server, both using Cloudflare Proxied DNS.

When sending events from the API server to the Umami API, we need Umami to receive the client's IP address instead of the API server's IP address. To achieve this, we must:

  1. Set an environment variable in Umami: CLIENT_IP_HEADER = x-forwarded-for
  2. Include the header: x-forwarded-for = client's IP in the request

Without these settings, Umami's detection logic would prioritize getting the API server's IP address.

After setting CLIENT_IP_HEADER = x-forwarded-for, Umami can now successfully obtain the client's IP address. However, there's another issue: Umami's location detection code bypasses the IP-based location lookup and directly uses the cf-ipcountry header. Since Umami also uses Cloudflare Proxied DNS, this means the location information will always correspond to the API server's location rather than the client's.

We need to forward the location information provided by Cloudflare to Umami, so I've added three additional environment variables.

'x-forwarded-for': ip,
'x-ipcountry': req.header('cf-ipcountry'),
'x-ipregion-code': req.header('cf-region-code'),
'x-ipcity': req.header('cf-ipcity')

@mikecao
Copy link
Collaborator

mikecao commented Jan 11, 2025

How about we create an environment variable IGNORE_LOCATION_HEADERS, if set then it will skip the CF/Vercel sections and fall back to using the IP database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants