Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions SUBDOMAIN_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Subdomain Support Implementation

This implementation adds subdomain support to the Neploy application deployment platform, allowing applications to be accessed via subdomains instead of only path-based routing.

## Features Added

### 1. Backend Changes

- **Enhanced Gateway Model**: Added `Subdomain` and `EndpointType` fields to support both routing types
- **Flexible Deployment**: Modified application deployment to accept endpoint type and domain configuration
- **Smart Router**: Updated gateway router to handle both subdomain and path-based routing
- **Service Layer**: Enhanced gateway service with subdomain creation and management

### 2. Frontend Changes

- **Configuration UI**: Added endpoint type selection to application deployment form
- **Domain Configuration**: Added domain input field for subdomain routing
- **Enhanced Gateway Table**: Updated to show endpoint type and appropriate URL format
- **Type Safety**: Added proper TypeScript types for subdomain configuration

## Usage

### Path-based Routing (Default)
- **URL Pattern**: `domain.com/appname`
- **Configuration**: Select "Path-based" in deployment form
- **Example**: `localhost/myapp` or `company.com/api`

### Subdomain Routing (New)
- **URL Pattern**: `appname.domain.com`
- **Configuration**: Select "Subdomain" in deployment form and specify domain
- **Example**: `myapp.localhost` or `api.company.com`

## Technical Implementation

### Gateway Model
```go
type Gateway struct {
Domain string `json:"domain"`
Subdomain string `json:"subdomain"`
Path string `json:"path"`
EndpointType string `json:"endpointType"` // "subdomain" or "path"
// ... other fields
}
```

### Route Matching Logic
- **Subdomain**: Matches `Host` header against `subdomain.domain`
- **Path**: Matches URL path prefix against configured path

### Database Schema
The existing database already supported subdomains with:
- `subdomain` column for subdomain value
- `endpoint_type` column with constraint `('subdomain', 'path')`
- Unique constraints for both subdomain and path routing

## Benefits

1. **Flexibility**: Companies can choose their preferred routing method
2. **Clean URLs**: Subdomain routing provides cleaner, more professional URLs
3. **Separation**: Better logical separation of applications
4. **Backward Compatibility**: Existing path-based deployments continue to work

## Example Deployment Flow

1. User deploys an application called "blog"
2. Selects "Subdomain" endpoint type
3. Specifies domain as "company.com"
4. Application becomes accessible at `blog.company.com`
5. Gateway table shows endpoint type and full URL

## Testing

Basic tests have been added to verify:
- Route key generation for both types
- Subdomain and path matching logic
- Route validation

Run tests with: `go test ./pkg/gateway -v`
19 changes: 1 addition & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/joho/godotenv v1.5.1
github.com/labstack/echo/v4 v4.13.3
github.com/lib/pq v1.10.9
github.com/mholt/archives v0.0.0-20241216060121-23e0af8fe73d
github.com/mssola/user_agent v0.6.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
Expand All @@ -37,15 +36,9 @@ require (
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/STARRY-S/zip v0.2.1 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/bodgit/plumbing v1.3.0 // indirect
github.com/bodgit/sevenzip v1.6.0 // indirect
github.com/bodgit/windows v1.0.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
Expand All @@ -58,14 +51,9 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
Expand All @@ -75,16 +63,12 @@ require (
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nwaples/rardecode/v2 v2.0.0-beta.4.0.20241112120701-034e449c6e78 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sorairolake/lzip-go v0.3.5 // indirect
github.com/src-d/gcfg v1.4.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/swaggo/files/v2 v2.0.1 // indirect
github.com/therootcompany/xz v1.0.1 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
Expand All @@ -95,7 +79,6 @@ require (
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
Expand Down
Loading