User IP from request, does Replit use proxy or load balancer

Sorry for dumb question if it is, but how can i get user IP from request on my NodeJs express app?

req.socket.remoteAddress or X-Forwarded-For wich used in request-ip package doesnt work here on Replit, it send me only server IP i guess.

Is it use proxy or load balancer here? If yes, can you guys please provide some information how can i get user ip other way

1 Like

Why do you need to get your users IP?

I use weather block on my website and i need to show current weather in user location.

Strange question, anyway. Any website logs users ip for stats, targeting or else

Couldn’t you just ask them for their location instead? Unless someone else here knows how to get the IP.

1 Like

yeah, i already ask user for location if they press on location button, but i want to implement some feature to get it instantly, and not disturb with notification or so

Try using the first IP sent in X-Forwarded-For

Have you tried using req.socket.remoteAddress or X-Forwarded-For directly?

On my endpoint that fetches your IP Address (https://api.valiantwind.dev/get-ip-address) I use this:

router.get("/get-ip-address", async (req: Request, res: Response) => {
	const ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress
	res.end(ip)
})

That might work for you instead of using request-ip.

The X-Forwarded-For header can contain user-provided information, so you should definitely parse it.

thanks man, but i already tried all of this

req.headers[‘x-forwarded-for’]
req.clientIp
req.ip
req.socket.remoteAddress

i already tried from all browsers, all devices , wifi/4g doesnt metter.

and all the time in results i have not my ip or undefined

can combined app be the reason of it?

i was deployed combined app nodejs/react

Can you check and see if pasting https://api.valiantwind.dev/get-ip-address into the url bar returns your ip address? I just want to check and see if it works for you. It’ll help me solve your issue.

yeah, it returns mine, and if i use inbuilt Webview on replit - its also return mine,

but when i tried to use my domain i linked - it return US ip adress (im not from US)

Can I see the code you’re using currently?

yeah, i guess i found the problem.

when i use domain that gave me Replit (this long ass link) - it returns my ip

but when i use custom domain i linked to this project - it returns wrong

1 Like

That’s strange, because AFAIK custom domains aren’t supported to do that (my endpoint is an example of this).

I’m glad you’ve found the issue :slight_smile:

1 Like

yeah, issue was found, but i don’t know how can i fix it)))

will wait for support answear

thanks for your help anyway)

1 Like

Same issue happening to me, can’t get the IP accurately on my custom domain. Works perfectly on Replit domain.

1 Like

Are you using Cloudflare? If so, try disabling Cloudflare proxying.

1 Like

I don’t know how to get the client IP address,
but I am pretty sure that replit doesn’t use a load balancer,
because replit allocates all of your repls a certain amount of VCPUs, RAM, and storage.
If replit used a load balancer, they would need to allocate resources more than once.

I’m fairly certain they do, as at least two different subdomains I have issued use the same IP address.

Thanks for the info!