openpanel icon indicating copy to clipboard operation
openpanel copied to clipboard

BUG: Geolocation shows server location instead of client location when using proxy route handler

Open Karnak19 opened this issue 1 month ago • 6 comments

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.

Karnak19 avatar Nov 12 '25 11:11 Karnak19

I assume you self-host? Are you behind cloudflare by any chance? And how do you self-host OpenPanel?

lindesvard avatar Nov 12 '25 22:11 lindesvard

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

Karnak19 avatar Nov 13 '25 07:11 Karnak19

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.

lindesvard avatar Nov 13 '25 15:11 lindesvard

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

Karnak19 avatar Nov 16 '25 01:11 Karnak19

Which header showed your real IP?

lindesvard avatar Nov 17 '25 13:11 lindesvard

Both of them had my IP

Karnak19 avatar Nov 17 '25 14:11 Karnak19

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.

lindesvard avatar Dec 02 '25 21:12 lindesvard