BUG: Geolocation shows server location instead of client location when using proxy route handler
Problem
When using createNextRouteHandler with a custom apiUrl to proxy requests through a Next.js API route, all users are detected as being from the server's location (Canada in my case) instead of their actual client location.
Environment
- OpenPanel Version:
@openpanel/nextjs@^1.0.9 - Next.js Version: 16.x
- Deployment: Self-hosted server using Coolify
Setup
I'm using a proxy route handler to forward OpenPanel requests:
// src/app/api/op/[...op]/route.ts
import { createNextRouteHandler } from "@openpanel/nextjs/server";
export const POST = createNextRouteHandler({
apiUrl: "https://xxxxxxxxxxxxxxxxxxxxxx.dev/",
});
And the client-side component:
<OpenPanelComponent
apiUrl="/api/op/op"
cdnUrl="/op1.js"
clientId="edbab56d-7f12-4a44-b3b3-6be45aad90b0"
trackScreenViews={true}
/>
Expected Behavior
OpenPanel should detect the client's IP address and use that for geolocation, showing users from their actual locations.
Actual Behavior
All users appear to be from Canada (the server's location), making geolocation data inaccurate. The dashboard shows 100% of users from Canada, which is clearly incorrect.
I assume you self-host? Are you behind cloudflare by any chance? And how do you self-host OpenPanel?
I assume you self-host? Are you behind cloudflare by any chance? And how do you self-host OpenPanel?
It's hosted using Coolify and not behind Cloudflare. I forgot to add, my Nextjs website is indeed behind Cloudflare
Can you deploy this app on coolify lindesvard/openpanel-geo-test:latest (expose port 3000)
Visit the provided URL and share which header is correct.
Can you deploy this app on coolify
lindesvard/openpanel-geo-test:latest(expose port 3000)Visit the provided URL and share which header is correct.
Sorry I'm not sure to understand correctly but I see x-forwarded-for and x-real-ip having some values (in addition with requestId and getIpAddress
Which header showed your real IP?
Both of them had my IP
With the new self-hosting release (which will be released this or next week) you'll be able to pick what header the server should take the IP from. So will close this issue since it will be configurable.