2.7 KiB
Caprover Integration Setup
This document explains how to set up the integration between the DZone API and Caprover for automatic domain configuration.
Overview
When a user successfully verifies their domain, the system will automatically configure that domain in Caprover, enabling the domain to be properly routed to the frontend application.
Configuration Steps
1. Set Environment Variables
Add the following environment variables to your .env file:
CAPROVER_API_URL=https://captain.dev.danakcorp.com/api/v2
CAPROVER_EMAIL=your_caprover_email@example.com
CAPROVER_PASSWORD=your_caprover_password
CAPROVER_APP_NAME=dzone-front
The system will automatically handle authentication with Caprover using these credentials and refresh tokens as needed.
2. Verify Configuration
- Restart the API service to apply the new environment variables
- Try verifying a domain through the API
- Check the logs to ensure the Caprover API calls are successful
How Token Refresh Works
The system automatically handles Caprover authentication:
- When a domain configuration request is made, the system checks if it has a valid token
- If no token exists or the token is about to expire (within 5 minutes), it requests a new one
- The system uses the email and password to authenticate with Caprover
- The new token is stored and used for subsequent requests
- Tokens are typically valid for 24 hours, but the system refreshes them after 23 hours to be safe
This approach ensures that the integration continues to work even if tokens expire.
Troubleshooting
Authentication Issues
If you see authentication errors in the logs:
- Verify that the
CAPROVER_EMAILandCAPROVER_PASSWORDare correct - Check that the user has sufficient permissions in Caprover
- Ensure the Caprover instance is accessible at the URL specified in
CAPROVER_API_URL
API Connection Issues
If the API cannot connect to Caprover, check:
- That the Caprover instance is running and accessible
- That the
CAPROVER_API_URLis correct - That there are no network issues between the API server and Caprover
Domain Configuration Issues
If domains are not being properly configured in Caprover:
- Check that the domain has proper DNS records pointing to your server
- Verify that the app name specified in
CAPROVER_APP_NAMEexists in Caprover - Ensure the Caprover user associated with the credentials has sufficient permissions
Manual Configuration
If automatic configuration fails, you can manually configure domains using the admin endpoint:
POST /business/domain/configure-caprover
This endpoint requires authentication and a business with a verified domain.