feat(acme): Improve certificate management by adding global ACME configuration support and allowing route-level overrides. Enhanced error messages help identify missing ACME email and misconfigurations (e.g. wildcard domains). Documentation has been updated and new tests added to verify SmartCertManager behavior, ensuring a clearer migration path from legacy implementations.

This commit is contained in:
2025-05-18 18:29:59 +00:00
parent ac4645dff7
commit 68738137a0
14 changed files with 706 additions and 1472 deletions

View File

@ -134,6 +134,14 @@ import {
// Create a new SmartProxy instance with route-based configuration
const proxy = new SmartProxy({
// Global ACME settings for all routes with certificate: 'auto'
acme: {
email: 'ssl@example.com', // Required for Let's Encrypt
useProduction: false, // Use staging by default
renewThresholdDays: 30, // Renew 30 days before expiry
port: 80 // Port for HTTP-01 challenges
},
// Define all your routing rules in a single array
routes: [
// Basic HTTP route - forward traffic from port 80 to internal service
@ -141,7 +149,7 @@ const proxy = new SmartProxy({
// HTTPS route with TLS termination and automatic certificates
createHttpsTerminateRoute('secure.example.com', { host: 'localhost', port: 8080 }, {
certificate: 'auto' // Use Let's Encrypt
certificate: 'auto' // Uses global ACME settings
}),
// HTTPS passthrough for legacy systems
@ -350,6 +358,66 @@ interface IRouteAction {
}
```
### ACME/Let's Encrypt Configuration
SmartProxy supports automatic certificate provisioning and renewal with Let's Encrypt. ACME can be configured globally or per-route.
#### Global ACME Configuration
Set default ACME settings for all routes with `certificate: 'auto'`:
```typescript
const proxy = new SmartProxy({
// Global ACME configuration
acme: {
email: 'ssl@example.com', // Required - Let's Encrypt account email
useProduction: false, // Use staging (false) or production (true)
renewThresholdDays: 30, // Renew certificates 30 days before expiry
port: 80, // Port for HTTP-01 challenges
certificateStore: './certs', // Directory to store certificates
autoRenew: true, // Enable automatic renewal
renewCheckIntervalHours: 24 // Check for renewals every 24 hours
},
routes: [
// This route will use the global ACME settings
{
name: 'website',
match: { ports: 443, domains: 'example.com' },
action: {
type: 'forward',
target: { host: 'localhost', port: 8080 },
tls: {
mode: 'terminate',
certificate: 'auto' // Uses global ACME configuration
}
}
}
]
});
```
#### Route-Specific ACME Configuration
Override global settings for specific routes:
```typescript
{
name: 'api',
match: { ports: 443, domains: 'api.example.com' },
action: {
type: 'forward',
target: { host: 'localhost', port: 3000 },
tls: {
mode: 'terminate',
certificate: 'auto',
acme: {
email: 'api-ssl@example.com', // Different email for this route
useProduction: true, // Use production while global uses staging
renewBeforeDays: 60 // Route-specific renewal threshold
}
}
}
}
**Forward Action:**
When `type: 'forward'`, the traffic is forwarded to the specified target:
```typescript