exportasyncfunctionloader({ request }: Route.LoaderArgs) { // using the request letipAddress = getClientIPAddress(request); // or using the headers letipAddress = getClientIPAddress(request.headers); }
If it can't find he IP address the return value will be null. Remember to check if it was able to find it before using it.
The function uses the following list of headers, in order of preference:
X-Client-IP
X-Forwarded-For
HTTP-X-Forwarded-For
Fly-Client-IP
CF-Connecting-IP
Fastly-Client-Ip
True-Client-Ip
X-Real-IP
X-Cluster-Client-IP
X-Forwarded
Forwarded-For
Forwarded
DO-Connecting-IP
oxygen-buyer-ip
When a header is found that contains a valid IP address, it will return without checking the other headers.
Warning
On local development the function is most likely to return null. This is because the browser doesn't send any of the above headers, if you want to simulate those headers you will need to either add it to the request Remix receives in your HTTP server or run a reverse proxy like NGINX that can add them for you.
Install using
bunx shadcn@latest add @remix-utils/get-client-ip-address.This depends on
is-ip.This function receives a Request or Headers objects and will try to get the IP address of the client (the user) who originated the request.
If it can't find he IP address the return value will be
null. Remember to check if it was able to find it before using it.The function uses the following list of headers, in order of preference:
When a header is found that contains a valid IP address, it will return without checking the other headers.
On local development the function is most likely to return
null. This is because the browser doesn't send any of the above headers, if you want to simulate those headers you will need to either add it to the request Remix receives in your HTTP server or run a reverse proxy like NGINX that can add them for you.Author
Sergio XalambrÃ