Skip to main content

Overview

Every DeployHub project can be accessed via a subdomain or a custom domain. Subdomains are automatically generated during project creation and can be updated at any time.

Domain Structure

Projects support two types of domains:

Subdomain

Automatically generated: {name}-{random}.deployhub.online

Custom Domain

Your own domain: www.example.com

Get Project Domains

GET /api/projects/:id/domains

Retrieve domain configuration for a project.
Authentication Required: Yes (JWT) Path Parameters:
string
required
Project ID (MongoDB ObjectId)
Response:
With Custom Domain:

Subdomain Generation

Subdomains are automatically generated during project creation using this algorithm:

Generation Logic

Subdomain Format

string
Format: {project-name}-{6-char-random}
  • Project name is converted to lowercase
  • Random string is 6 characters (base-36: 0-9, a-z)
  • Up to 20 attempts to ensure uniqueness
Example: my-website-a3f5k2

Full URL

The complete domain is: {subdomain}.deployhub.online Example: https://my-website-a3f5k2.deployhub.online

Update Subdomain

PATCH /api/projects/:id/domains/subdomain

Change the subdomain for a project. This triggers a container rebuild.
Authentication Required: Yes (JWT) Request Body:
string
required
New subdomain (without .deployhub.online)Validation: Must match pattern /^[a-z0-9-]{3,40}$/
  • Only lowercase letters, numbers, and hyphens
  • Length: 3-40 characters
Example Request:
Response:

Subdomain Validation

Valid Examples:
  • my-site
  • production-app-2024
  • web-app-v2
  • my-project
Invalid Examples:
  • My-Site (uppercase not allowed)
  • my_site (underscores not allowed)
  • ab (too short, minimum 3 characters)
  • my.site (dots not allowed)

Uniqueness Check

The uniqueness check excludes the current project and deleted projects.

Subdomain Update Process

When updating a subdomain, several operations occur:

1. Update Project Status

The project status is set to "building" during the subdomain transition.

2. Update Binding

The Binding model tracks the port allocation for the subdomain.

3. Update Redis Cache

Redis is used for fast subdomain-to-project routing.

4. Queue Container Rebuild

A worker recreates the Docker container with the new subdomain.

Binding Model

The Binding model manages domain-to-port mappings:
Index: subdomain field is indexed for fast lookups

Port Allocation

For static projects:
For Node.js projects:

Custom Domains

Custom domains are tracked in the project model:
Custom domain configuration endpoints are not shown in the provided source code. Custom domain setup may require additional DNS configuration and SSL certificate generation.

Redis Caching Strategy

Subdomains are cached in Redis for fast request routing: Key Format: subdomain:{subdomain-name} Cached Data:
This allows the reverse proxy to quickly determine which container to route requests to without querying the database.

Example: Update Subdomain

Error Responses

400 Bad Request - Invalid Format

404 Not Found

409 Conflict

500 Server Error

Security Considerations

Ownership Verification

All domain operations verify that the authenticated user owns the project

Uniqueness Enforcement

Subdomain uniqueness is enforced at the database level with indexed queries

Status Filtering

Deleted projects are excluded from subdomain availability checks

Redis Sync

Redis cache is updated atomically with database changes

Domain Display Logic

When displaying a project’s domain, use this logic:
This ensures custom domains take precedence when configured.