Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 22, 2025

This PR implements subdomain support for applications, allowing companies to choose between path-based routing (domain.com/appname) and subdomain routing (appname.domain.com).

Overview

Previously, applications could only be accessed via path-based routing (e.g., company.com/api). This implementation adds support for subdomain routing (e.g., api.company.com), providing companies with more flexibility in how they structure their application URLs.

Changes Made

Backend Implementation

Gateway Model Enhancement:

  • Added Subdomain and EndpointType fields to the Gateway model to match the existing database schema
  • Updated request models to include subdomain configuration options

Routing Logic:

  • Enhanced the gateway router to support both subdomain and path-based matching
  • Subdomain routes match against the Host header (appname.domain.com)
  • Path routes continue to match against URL paths (/appname)
  • Added proper route key generation for both endpoint types

Deployment Process:

  • Modified the application deployment service to accept endpoint type and domain parameters
  • Updated the deployment handler to process subdomain configuration
  • Enhanced gateway creation to support both routing types

Frontend Implementation

Deployment Form:

  • Added endpoint type selection dropdown with "Path-based" and "Subdomain" options
  • Added dynamic domain configuration field that appears when subdomain is selected
  • Enhanced form validation and TypeScript types

Gateway Management:

  • Updated gateway table to display endpoint type badges
  • Shows appropriate URL format based on endpoint type (path vs subdomain)
  • Enhanced visual distinction between routing types

Technical Details

The implementation leverages the existing database schema which already included subdomain support:

  • subdomain column for storing subdomain values
  • endpoint_type column with constraint ('subdomain', 'path')
  • Unique constraints for both routing types

The router now handles both endpoint types:

if route.EndpointType == "subdomain" {
    // Match against Host header
    expectedHost := route.Subdomain + "." + route.Domain
    matches = strings.HasPrefix(host, expectedHost)
} else {
    // Match against URL path
    matches = strings.HasPrefix(path, route.Path)
}

User Experience

Users can now:

  1. Deploy applications with subdomain routing by selecting "Subdomain" in the deployment form
  2. Configure custom domains for subdomain routing
  3. View all gateway configurations with clear endpoint type indicators
  4. Seamlessly switch between routing types for different applications

Testing

Added comprehensive unit tests covering:

  • Route key generation for both endpoint types
  • Subdomain and path matching logic
  • Route validation and error handling

All tests pass: go test ./pkg/gateway -v

Backward Compatibility

Existing path-based deployments continue to work unchanged. The default endpoint type remains "path" to ensure compatibility.

Subdomain Support UI

Fixes #178.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Add subdomain support Add subdomain support for application routing Sep 22, 2025
@Copilot Copilot AI requested a review from henrriusdev September 22, 2025 15:40
Copilot finished work on behalf of henrriusdev September 22, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add subdomain support

2 participants