How do I access my user's public IP?

I'm using a FastAPI as the backend for our app, and have migrated it from our VPS to Railway a few days ago. I noticed that this line of code, isn't returning the client's Public IP anymore, and is instead returning IPs in the range 192.168.0.X:
# Get client IP
ip = str(request.client.host)
# Get client IP
ip = str(request.client.host)
How do I fix it? Project ID: 9104e677-99c1-48c6-bbe8-41942e8c5fa2
Solution:
your app sits behind a proxy when on railway, the clients ip can be found by trusting the X-Envoy-External-Address header https://utilities.up.railway.app/raw...
Jump to solution
5 Replies
Percy
Percy13mo ago
Project ID: 9104e677-99c1-48c6-bbe8-41942e8c5fa2
hellosendpie
hellosendpieOP13mo ago
9104e677-99c1-48c6-bbe8-41942e8c5fa2
Solution
Brody
Brody13mo ago
your app sits behind a proxy when on railway, the clients ip can be found by trusting the X-Envoy-External-Address header https://utilities.up.railway.app/raw
hellosendpie
hellosendpieOP13mo ago
Got it, I'll check it it. Thanks Brody! Does railway's proxy automatically mitigate DDOS attacks? Or is it recommended to have Cloudflare still handle that?
Brody
Brody13mo ago
railway does not advertise ddos protection, if thats a concern youd want to use cloudflare cloudflare has their own header for the client ip https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-connecting-ip
Want results from more Discord servers?
Add your server