Subdomain & Wildcard Routing (F3.2) β
Feature: F3.2 β Subdomain Support
Status: π’ COMPLETED
Package:@vexlyx/api,@vexlyx/dashboard,@vexlyx/shared
Prisma Models:Domain,Project,DnsRecord
1. Overview β
Subdomain & Wildcard Routing enables Vexlyx users to route traffic from multiple subdomains (api.domain.com, blog.domain.com, app.domain.com) or wildcard catch-alls (*.domain.com) to different project containers on the same server with zero downtime.
Drawing from modern PaaS patterns (Vercel, Coolify, Cloudflare), Vexlyx implements Account-Level Ownership Inheritance: once an apex domain (domain.com) is verified via DNS TXT record, any subsequent subdomains or wildcards created under that parent domain automatically inherit verification status and are immediately activated (ACTIVE), generating Traefik dynamic router definitions on the fly.
2. Architecture & Data Flow β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js Dashboard UI β
β - /domains (Global domain overview & Subdomain manager) β
β - SubdomainModal (Prefix input, wildcard toggle, project) β
β - Project detail /projects/[id] (DomainPanel) β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β HTTP / JSON
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Fastify API Server β
β - POST /api/domains (Create subdomain) β
β - GET /api/domains (List domains/subdomainsβ
β - GET /api/domains/:id/subdomains (List child subdomains)
β - POST /api/domains/:id/verify (DNS TXT verification) β
β - DELETE /api/domains/:id (Cascade deletion) β
βββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β PostgreSQL (Prisma) β β Traefik v3 Dynamic File β
β - model Domain β β docker/traefik/dynamic/ β
β * hostname (e.g. *.dom.com)β β domain-{domainId}.yml β
β * parentId (relation) β βββββββββββββββ¬ββββββββββββββ
β * pathPrefix (e.g. /api) β β Hot-reloaded
β * status (PENDING/ACTIVE) β βΌ
β - subdomains Domain[] β βββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββ β Traefik v3 Reverse Proxy β
β Specific Host priority 100β
β Wildcard Host priority 10 β
βββββββββββββββββββββββββββββ3. Key Technical Decisions & Mechanisms β
1. Account-Level Verification Inheritance β
- Proving ownership of an apex domain (
domain.com) via DNS TXT challenge claims that domain for the user account. - When creating any subdomain (
api.domain.com) or wildcard (*.domain.com) where the parent domain is already verified (ACTIVE), the subdomain is immediately markedACTIVEwithout prompting for repetitive DNS challenges. - Traefik dynamic routing is configured immediately upon creation.
2. Traefik Dynamic Router Prioritization β
When both specific subdomains and wildcard domains exist for the same apex domain (e.g., api.domain.com and *.domain.com), Traefik router rules are assigned deterministic priorities:
- Specific Subdomains:
priority: 100(rule: Host(\api.domain.com`)`) - Wildcard Subdomains:
priority: 10(rule: Host(\*.domain.com`)`) - Path Prefixes (Optional):
rule: Host(\...`) && PathPrefix(`${pathPrefix}`)`
Incoming traffic to api.domain.com always matches the specific project container, while unmatched subdomains (anything.domain.com) smoothly fall back to the wildcard project container.
3. Wildcard DNS Verification Target β
If a user adds a wildcard subdomain (*.domain.com) standalone without having previously verified domain.com, the DNS TXT challenge is automatically targeted to _vexlyx-challenge.domain.com (stripping *. so resolvers can query valid TXT records).
4. Cascade Cleanup β
Deleting a parent domain unlinks the Traefik configuration files for all child subdomains and cascades in the database.
4. API Reference β
POST /api/domains β
Create a domain, subdomain, or wildcard subdomain.
- Request Body:json
{ "hostname": "api.mydomain.com", "parentId": "dom_parent123", // optional "projectId": "proj_abc456", // optional "pathPrefix": "/v1" // optional } - Response (201 Created):json
{ "id": "dom_child789", "hostname": "api.mydomain.com", "status": "ACTIVE", // inherited if parent is ACTIVE "parentId": "dom_parent123", "projectId": "proj_abc456", "isWildcard": false, "pathPrefix": "/v1" }
GET /api/domains/:id/subdomains β
Lists all subdomains attached to a specific parent domain.
5. Testing β
Run the automated test suite:
python tests/test_subdomains.py
python tests/test_custom_domains.pyCovered test cases:
test_acceptance_criteria_subdomains: Validatesapi.domain.com,blog.domain.com,app.domain.com,*.domain.com.test_invalid_wildcards_and_subdomains: Rejects*.com,*.*.com,*domain.com, spaces, and invalid formats.test_subdomain_helpers: ValidatesisWildcardHostname,getParentDomain, andisSubdomain.test_traefik_router_priorities: Validates priority 100 for specific subdomains and priority 10 for wildcards.test_verification_inheritance: Verifies automatic activation when parent domain is active.test_unauthorized_access: Verifies 401 unauthorized protection on API routes.