Project Domains
Projects
Project Domains
Retrieve and update domain configuration for a project
GET
Project Domains
Get Project Domains
The unique identifier of the project (MongoDB ObjectId)
Authentication
Requires JWT authentication via theverifyJWT middleware.
Response
Indicates whether the request was successful
Domain configuration for the project
Example Request
Example Response
Example Response (With Custom Domain)
Update Subdomain
Update the DeployHub subdomain for a project. This triggers a container recreation with the new subdomain.Path Parameters
The unique identifier of the project
Request Body
The new subdomain. Must be 3-40 characters long, containing only lowercase letters, numbers, and hyphens.
Validation Rules
- Pattern: Must match regex
/^[a-z0-9-]{3,40}$/ - Length: 3-40 characters
- Characters: Lowercase letters (a-z), numbers (0-9), hyphens (-) only
- Uniqueness: Subdomain must not be taken by another active project
- Invalid examples:
MY-APP(uppercase not allowed)my_app(underscores not allowed)ab(too short)my app(spaces not allowed)
Behavior
- Validates subdomain format and uniqueness
- Updates the subdomain in the project document
- Sets project status to
building - Updates the port binding allocation
- Updates Redis cache with new subdomain mapping
- Queues a container recreation job
- Project will rebuild and restart with the new subdomain
Example Request
Example Response
Error Responses
400 Bad Request - Invalid Format
Returned when the subdomain doesn’t meet validation requirements
404 Not Found
Returned when:
- Project with the specified ID doesn’t exist
- Project doesn’t belong to the authenticated user
- Project has been deleted
409 Conflict
Returned when the subdomain is already taken by another project
500 Internal Server Error
Returned when a server error occurs during the update process
Implementation Notes
Subdomain Update Process
-
Validation Phase:
- Checks subdomain format using regex validation
- Queries database to ensure subdomain is not already taken
- Ignores the current project when checking uniqueness
- Excludes deleted projects from uniqueness check
-
Update Phase:
- Updates project document with new subdomain
- Sets status to
building(bypasses validation) - Updates the Binding (port allocation) document
- Removes old subdomain from Redis cache
- Creates new Redis cache entry with port mapping
-
Recreation Phase:
- Queues a job to
deployhub-recreate-containerqueue - Job data includes:
projectId,oldcontainername,newcontainername - Container is recreated with the new subdomain
- Project becomes accessible at
{new-subdomain}.deployhub.online
- Queues a job to
Redis Cache Structure
The subdomain cache stores:- Key:
subdomain:{subdomain} - Value (hash):
port: Internal port number for routingprojectId: Project identifierplan: Subscription plan for rate limiting
Downtime
Updating a subdomain causes temporary downtime as the container is recreated. During this time:- Project status is
building - The old subdomain becomes inaccessible
- The new subdomain is not yet available
- Typical recreation time: 1-3 minutes depending on project size
Custom Domains
This endpoint only handles DeployHub subdomains. Custom domain configuration (for pro plan users) is handled separately and requires DNS verification.Source Reference
- GET domains:
backend/src/controllers/slices/Project/domain.controller.js:6 - PATCH subdomain:
backend/src/controllers/slices/Project/domain.controller.js:29