This is a TypeScript Express application that dynamically updates DNS records on Cloudflare with the current public IP address of the server. It uses the Cloudflare API to perform the updates and includes authentication via API key.
- Fetches the current public IP address using the ipify API
- Updates specified DNS records in Cloudflare API with the current IP address
- Secured with an API key to prevent unauthorized access
- Includes unique request IDs for all API responses
- Provides human-friendly JSON responses with automatic pretty-printing
- Clear separation between public and protected endpoints
npm install cloudflare-dyndns-updater
- Clone the repository:
git clone https://github.com/rdp-datacenter/ip-update.git
- Navigate to the project directory:
cd ip-update
- Install dependencies:
npm install
- Build the TypeScript files:
npm run build
- Node.js (v14 or higher recommended)
- npm or yarn
- A Cloudflare account with API credentials
- An
.env
file with the necessary configuration values
Create a .env
file in the root directory with the following variables:
PORT
: Port number for the Express server (default is 5555)CF_DNS
: Comma-separated list of Cloudflare DNS record IDs that you want to updateCF_ZONE
: Cloudflare Zone ID where DNS records are managedCF_MAIL
: Cloudflare Email address associated with the accountCF_AUTH
: Cloudflare API token for authenticationRDP_API_KEY
: Your own API key used to authenticate requests to this service
Example .env
file:
RDP_API_KEY=your_own_generated_key
CF_DNS=record1,record2,record3
CF_ZONE=your_cloudflare_zone_id
CF_MAIL=your_cloudflare_email
CF_AUTH=your_cloudflare_auth_token
PORT=3000
- Start the server:
npm start
- Access the service information by sending a GET request to the root endpoint:
curl -X GET http://localhost:5555/
- Update the DNS records by sending a GET request to the update endpoint with your API key:
Or using the header method:
curl -X GET http://localhost:5555/update?api_key=<your-secure-api-key>
curl -X GET -H "rdp-key: <your-secure-api-key>" http://localhost:5555/update
const { app } = require('cloudflare-dyndns-updater');
// Or with ES Modules
// import { app } from 'cloudflare-dyndns-updater';
// You can now use the Express app instance
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`DNS updater running on port ${port}`);
});
Returns information about the service and available endpoints.
Response:
{
"name": "RDP DNS Updater",
"version": "1.0.0",
"request_id": "9ABCDD4CC53F2BC1-RDP",
"endpoints": [
{ "path": "/update", "method": "GET", "description": "Update DNS records with current IP (requires API key)" },
{ "path": "/health", "method": "GET", "description": "Service health check (no auth required)" },
{ "path": "/update-all", "method": "GET", "description": "Update all DNS records (requires API key)" }
],
"status": "operational"
}
Updates the DNS records with the current public IP address. Requires an API key.
Authentication:
- Header:
rdp-key: <your-api-key>
- Or Query Parameter:
api_key=<your-api-key>
Response (Success):
{
"status": "success",
"ip": "76.76.21.21",
"request_id": "9ABCDD4CC53F2BC1-RDP",
"records": [
{
"id": "record1",
"name": "dns.rdpdatacenter.in",
"success": true,
"status": 200
}
]
}
Response (Error):
{
"status": "failed",
"request_id": "9ABCDD4CC53F2BC1-RDP",
"error": "Error message details"
}
Checks if the service is running properly.
Response:
{
"status": "healthy",
"request_id": "9ABCDD4CC53F2BC1-RDP",
"timestamp": "2025-04-26T12:34:56.789Z"
}
Updates all configured DNS records. Requires an API key.
Authentication:
- Same as
/update
endpoint
Response:
{
"status": "success",
"request_id": "9ABCDD4CC53F2BC1-RDP",
"message": "All DNS records updated successfully"
}
Every API response includes a unique request ID in both the response headers (RDP-Request-ID
) and the response body (request_id
). These IDs can be used for debugging and tracking purposes.
For local development with automatic reloading:
npm run dev
You can run the application in a Docker container using either Docker directly or Docker Compose.
A docker-compose.yml
file is provided for easy deployment:
# Build and start the container
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the container
docker-compose down
# Build the Docker image
docker build -t ip-update .
# Run the container
docker run -p 5555:5555 --env-file .env ip-update
The Docker setup includes:
- Node.js slim image for a lightweight container
- Proper caching of npm dependencies
- Production mode settings
- Health checks via the
/health
endpoint - Volume mounting for logs
- Automatic container restart
This project is also configured for deployment on Vercel. The vercel.json
file includes the necessary configuration.
Feel free to submit issues, feature requests, or pull requests. Contributions are welcome!
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or issues, please contact [email protected].