Custom Domain Routing

Admin → Silver
đź’° $1000

Map and serve content through personalized domains or subdomains.

Technology iconTechnology iconTechnology icon

Overview: Custom Domain Routing Module

The Custom Domain Routing module empowers users to map content through personalized domains or subdomains, offering flexibility and control over how their application is presented online. Designed for developers and system administrators, this module enhances branding, SEO, and user trust by allowing custom domain configurations.

Purpose

Benefits

Usage Scenarios

  1. Personalized Websites: Each user can have a unique subdomain (e.g., client1.mysaas.com) or domain, providing a tailored experience.
  2. Marketing Campaigns: Different domains can be used for various regions or languages, enhancing localization efforts.
  3. Technical Configurations: Admins can set up DNS records (CNAME/A) and SSL certificates to ensure seamless integration with custom domains.

This module is essential for developers seeking to enhance their application’s online presence through flexible and secure domain management.

Key Features of Custom Domain Routing Module

1. Domain Mapping

2. DNS Record Management

3. Domain Validation

4. Wildcard Subdomain Support

5. SSL/TLS Certificate Management

6. Custom Domain Cleanup

7. Rate Limiting for Custom Domains

8. Caching for Optimized Performance

9. Logging and Monitoring

These features collectively provide a robust and flexible solution for managing custom domains, ensuring security, performance, and ease of use.

Custom Domain Routing Module Documentation

Overview

The Custom Domain Routing module allows administrators to map and serve content through personalized domains or subdomains. This module is designed for developers who need fine-grained control over domain routing configurations.


Key Features


Usage Examples

  1. Add a Custom Domain:
curl -X POST http://admin-panel/api/custom-domains \
  -H "Content-Type: application/json" \
  -d '{"domain": "example.com", "subdomain": "blog"}'
  1. Update an Existing Domain:
curl -X PUT http://admin-panel/api/custom-domains/123 \
  -H "Content-Type: application/json" \
  -d '{"domain": "newdomain.com", "subdomain": "api"}'

Code Samples

1. FastAPI Endpoint (Python)

from fastapi import APIRouter, Depends, HTTPException
from typing import Annotated
from pydantic import BaseModel

router = APIRouter(prefix="/api/custom-domains")

class CustomDomain(BaseModel):
    id: str
    domain: str
    subdomain: str
    is_active: bool = True
    created_at: str

# Mock database (replace with your DB)
custom_domains = []

@router.get("/", response_model=list[CustomDomain])
def get_custom_domains():
    return custom_domains

@router.post("/", response_model=CustomDomain)
def add_custom_domain(domain_data: CustomDomain):
    new_entry = domain_data.dict()
    custom_domains.append(new_entry)
    return new_entry

@router.put("/{domain_id}", response_model=CustomDomain)
def update_custom_domain(domain_id: str, domain_data: CustomDomain):
    for entry in custom_domains:
        if entry["id"] == domain_id:
            updated_entry = domain_data.dict()
            index = custom_domains.index(entry)
            custom_domains[index] = updated_entry
            return updated_entry
    raise HTTPException(status_code=404, detail="Custom Domain not found")

2. React UI Snippet (JavaScript/JSX)

import React, { useState } from 'react';

interface CustomDomainForm {
  id?: string;
  domain: string;
  subdomain: string;
}

export const CustomDomainManager = () => {
  const [domains, setDomains] = useState<CustomDomain[]>([]);
  const [newDomain, setNewDomain] = useState<CustomDomainForm>({});

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    if (newDomain.id) {
      // Update existing domain
      setDomains(domains.map(domain =>
        domain.id === newDomain.id ? { ...domain, ...newDomain } : domain
      ));
    } else {
      // Add new domain
      setDomains([...domains, { ...newDomain, id: Date.now().toString(), created_at: new Date().toISOString() }]);
    }
    setNewDomain({});
  };

  return (
    <div>
      <h1>Custom Domain Routing</h1>
      <form onSubmit={handleSubmit}>
        <input
          type="text"
          placeholder="Enter domain (e.g., example.com)"
          value={newDomain.domain || ""}
          onChange={(e) => setNewDomain({ ...newDomain, domain: e.target.value })}
        />
        <input
          type="text"
          placeholder="Enter subdomain (e.g., blog)"
          value={newDomain.subdomain || ""}
          onChange={(e) => setNewDomain({ ...newDomain, subdomain: e.target.value })}
        />
        <button type="submit">Add Domain</button>
      </form>
      <div>
        {domains.map(domain => (
          <div key={domain.id}>
            <h3>{domain.domain}</h3>
            <p>Subdomain: {domain.subdomain}</p>
            <p>Status: {domain.is_active ? 'Active' : 'Inactive'}</p>
          </div>
        ))}
      </div>
    </div>
  );
};

3. Pydantic Data Schema

from pydantic import BaseModel, Field
from typing import Optional

class BaseDomain(BaseModel):
    domain: str = Field(..., description="Primary domain name")
    subdomain: str = Field(..., description="Subdomain prefix")

class CustomDomain(BaseDomain):
    id: str = Field(..., description="Unique identifier for the custom domain")
    is_active: bool = Field(True, description="Indicates if the domain is active")
    created_at: str = Field(..., description="Timestamp when the domain was created")
    notes: Optional[str] = Field(None, description="Optional notes about the domain configuration")

Conclusion

The Custom Domain Routing module provides developers with robust tools to manage domain configurations. By leveraging FastAPI for backend routing and React for frontend management, you can efficiently map and serve content through personalized domains or subdomains.

Custom Domain Routing Module Documentation

Overview

The Custom Domain Routing module enables developers to map and serve content through personalized domains or subdomains, providing flexibility in domain management.

Use Cases

  1. Multi-Regional Support

    • Route traffic from eu.example.com to European servers and asia.example.com to Asian servers, ensuring localized content delivery.
  2. Custom Domain Portals

    • Allow users to set up portals like user123.example.com for personalized experiences.
  3. Path-Based Routing

    • Map /blog requests to blog.example.com, allowing subdomains for specific site sections.
  4. Wildcard Subdomains

    • Use *.example.com for various purposes, such as testing environments or customer-specific domains.

Integration Tips

Configuration Options

OptionDescription
Domain PatternsRegular expressions or exact strings to match domains.
Subdomain SupportEnable/disable subdomains for specific routes.
Routing RulesDefine rules based on paths (e.g., /blog) or hostnames (e.g., eu.example.com).
SSL SettingsEnforce HTTPS, enable SNI, configure certificates.
Session AffinityControl session cookies to maintain user context across domains.
Caching BehaviorSpecify caching strategies for domain-specific content.

Examples

This documentation provides a structured approach to integrating and managing custom domains, ensuring efficient and secure content delivery.