Skip to content

Custom Domain Feature Implementation Guide

Dhananjay Thomble edited this page Oct 6, 2023 · 2 revisions

Custom Domain Feature Implementation Guide

Overview

The custom domain feature allows users to use their own domain names to create short URLs. Instead of the standard format like https://dturl.live/api/url/j6_0VPS_0w, users can create short URLs like https://yourdomain.com/u/myShortURL. This feature adds a layer of personalization and branding to their shortened URLs.

Implementation Approach

To implement this feature, follow these steps:

1. DNS Configuration

  • What to Do: Users need to configure their DNS settings to point their custom domain (e.g., yourdomain.com) to our service. This is typically done through their domain registrar's control panel.

  • Guidance: Provide users with clear instructions and guidance on how to add specific DNS records (TXT records) with unique values to their DNS settings.

2. Domain Verification

  • What to Do: Implement a domain verification process to ensure that users actually own the custom domain they want to use.

  • Steps:

    • Generate unique verification codes for each user.

      • In this step, you need to generate unique verification codes for each user. These codes will be used to verify domain ownership.
      • You can use a cryptographic library to generate secure and unique codes.
    • Instruct users to add these verification codes as TXT records in their DNS settings.

      • Once you've generated the verification codes, provide users with their unique code.
      • Instruct users to add this verification code as a TXT record in their DNS settings for the custom domain they want to use.
      • Display the code to the user along with clear instructions on where and how to add it to their DNS settings.

      // Pseudo code

      const userVerificationCode = generateVerificationCode();

      console.log(``Please add the following TXT record to your DNS settings: ${userVerificationCode}``)

    • Periodically check for the presence of these codes in DNS records to confirm domain ownership.

      • Implement a periodic check to confirm domain ownership.
      • Retrieve the user's DNS records and check if the verification code is present in their DNS records.
      • If the code is found, domain ownership is confirmed. Otherwise, instruct the user to ensure that the TXT record is correctly added to their DNS settings
      • Set up a scheduled task or cron job to periodically run the DNS record check function.

// Pseudo code

function checkDomainOwnership() {

const userDnsRecords = getUserDnsRecords();

if (userDnsRecords.includes(userVerificationCode)) {

console.log('Domain ownership confirmed.');

} else {

console.log('Domain ownership not confirmed. Please ensure the TXT record is correctly added.');

}

}

3. Routing Logic

  • What to Do: On the server side, create logic to recognize incoming requests with different hostnames (custom domains).

  • Steps:

    • When a request comes in with a custom domain, look up the user associated with that domain.
    • Redirect the user to the correct original URL based on the path part of the URL (e.g., /u/myShortURL).

4. Security Measures

  • What to Do: Implement security measures to ensure that users' custom domains are isolated from each other.

  • Steps:

    • Ensure that each user's short URLs are only accessible via their associated custom domains.
    • Implement user authentication and authorization checks to prevent unauthorized access.

5. Documentation and Support

  • What to Do: Update your project's README with clear instructions on how users can set up custom domains.

  • Guidance:

    • Create a troubleshooting section that addresses common domain configuration issues.
    • Later, we can set up a support channel for users via email or a forum.

Hints

  • You can use Express.js middleware for request handling, routing, and authentication.
  • Ensure that verification codes and user data are stored securely.
  • Test the entire process end-to-end to catch any issues.
  • Document each step clearly to help users with the setup.

By following these steps, we can provide our users with the ability to use their custom domains for shortening URLs, enhancing the personalization and branding of our URL-Shortener-App.