BREAKING CHANGE(smart-proxy): remove route helper APIs and standardize route configuration on plain route objects

This commit is contained in:
2026-03-26 20:45:41 +00:00
parent 47140e5403
commit 788ccea81e
32 changed files with 1159 additions and 2840 deletions

View File

@@ -462,35 +462,57 @@ For TLS termination modes (`terminate` and `terminate-and-reencrypt`), SmartProx
**HTTP to HTTPS Redirect**:
```typescript
import { createHttpToHttpsRedirect } from '@push.rocks/smartproxy';
import { SocketHandlers } from '@push.rocks/smartproxy';
const redirectRoute = createHttpToHttpsRedirect(['example.com', 'www.example.com']);
const redirectRoute = {
name: 'http-to-https',
match: { ports: 80, domains: ['example.com', 'www.example.com'] },
action: {
type: 'socket-handler' as const,
socketHandler: SocketHandlers.httpRedirect('https://{domain}:443{path}', 301)
}
};
```
**Complete HTTPS Server (with redirect)**:
```typescript
import { createCompleteHttpsServer } from '@push.rocks/smartproxy';
const routes = createCompleteHttpsServer(
'example.com',
{ host: 'localhost', port: 8080 },
{ certificate: 'auto' }
);
const routes = [
{
name: 'https-server',
match: { ports: 443, domains: 'example.com' },
action: {
type: 'forward' as const,
targets: [{ host: 'localhost', port: 8080 }],
tls: { mode: 'terminate' as const, certificate: 'auto' as const }
}
},
{
name: 'http-redirect',
match: { ports: 80, domains: 'example.com' },
action: {
type: 'socket-handler' as const,
socketHandler: SocketHandlers.httpRedirect('https://{domain}:443{path}', 301)
}
}
];
```
**Load Balancer with Health Checks**:
```typescript
import { createLoadBalancerRoute } from '@push.rocks/smartproxy';
const lbRoute = createLoadBalancerRoute(
'api.example.com',
[
{ host: 'backend1', port: 8080 },
{ host: 'backend2', port: 8080 },
{ host: 'backend3', port: 8080 }
],
{ tls: { mode: 'terminate', certificate: 'auto' } }
);
const lbRoute = {
name: 'load-balancer',
match: { ports: 443, domains: 'api.example.com' },
action: {
type: 'forward' as const,
targets: [
{ host: 'backend1', port: 8080 },
{ host: 'backend2', port: 8080 },
{ host: 'backend3', port: 8080 }
],
tls: { mode: 'terminate' as const, certificate: 'auto' as const },
loadBalancing: { algorithm: 'round-robin' as const }
}
};
```
### Smart SNI Requirement (v22.3+)