A simple Node.js application that returns the visitor's IP address. This app is designed to work with CapRover and handles various deployment scenarios including CloudFlare integration.
- Returns visitor's IP address
- Supports both IPv4 and IPv6
- Handles various proxy scenarios:
- Direct connections
- Behind CapRover proxy
- Behind CloudFlare
- Behind Nginx
- Behind Azure
- Multiple proxy layers
- Intelligent IP detection using headers:
- CF-Connecting-IP (CloudFlare)
- X-Forwarded-For (Standard proxy)
- X-Real-IP (Nginx)
- X-Client-IP (Azure)
- Direct socket connection
# Clone the repository
git clone https://github.com/EnkodoNL/caprover-return-ip.git
# Install dependencies
npm install
# Start the server
npm start
-
Create a new app in your CapRover dashboard
-
Deploy using one of these methods:
Make sure you have the CapRover CLI installed:
npm install -g caprover
caprover deploy
- Download the caprover-deploy.tar tarball from the Releases page
- Upload the tarball in the CapRover dashboard under "Method 2: Tarball"
- Push your code to GitHub
- Set up automatic deployment in CapRover dashboard using your repository URL
The application uses a hierarchical approach to determine the correct IP address:
- First checks for CloudFlare's
CF-Connecting-IP
header - Falls back to
X-Forwarded-For
header - Then checks
X-Real-IP
(Nginx) - Then checks
X-Client-IP
(Azure) - Finally uses the socket's remote address if no proxy headers are present
The app includes special handling for:
- IPv6 addresses with port information
- Multiple IP addresses in forwarded headers (takes the first one)
- Different IP address formats
- Port information removal
PORT
: Server port (default: 3000)FORMAT
: Response format- If not set: returns plain IP address
- If set to "json": returns JSON with IP and version
EMPTY_RESPONSE
: Custom response when IP cannot be determined (default: "x.x.x.x")
192.168.1.1
or
2001:db8::1
{
"ip": "192.168.1.1",
"version": "ipv4"
}
or
{
"ip": "2001:db8::1",
"version": "ipv6"
}
- Built with Node.js and Express
- Minimal dependencies for better security and performance
- Uses CapRover's Node.js 20 template
- Includes IP cleaning functionality:
- Removes port information
- Handles IPv6 addresses in brackets
- Extracts first IP from forwarded headers
- Automatic IP version detection (ipv4/ipv6)
MIT