BREAKING CHANGE(forwarding): Refactor unified forwarding API and remove redundant documentation. Removed docs/forwarding-system.md (its content is migrated into readme.md) and updated helper functions (e.g. replacing sniPassthrough with httpsPassthrough) to accept configuration objects. Legacy fields in domain configurations (allowedIPs, blockedIPs, useNetworkProxy, networkProxyPort, connectionTimeout) have been removed in favor of forwarding.security and advanced options. Tests and examples have been updated accordingly.
This commit is contained in:
@ -6,13 +6,13 @@ import type { IForwardConfig, ForwardingType } from '../ts/smartproxy/types/forw
|
||||
import { ForwardingHandlerFactory } from '../ts/smartproxy/forwarding/forwarding.factory.js';
|
||||
import { createDomainConfig } from '../ts/smartproxy/forwarding/domain-config.js';
|
||||
import { DomainManager } from '../ts/smartproxy/forwarding/domain-manager.js';
|
||||
import { httpOnly, tlsTerminateToHttp, tlsTerminateToHttps, sniPassthrough } from '../ts/smartproxy/types/forwarding.types.js';
|
||||
import { httpOnly, tlsTerminateToHttp, tlsTerminateToHttps, httpsPassthrough } from '../ts/smartproxy/types/forwarding.types.js';
|
||||
|
||||
const helpers = {
|
||||
httpOnly,
|
||||
tlsTerminateToHttp,
|
||||
tlsTerminateToHttps,
|
||||
sniPassthrough
|
||||
sniPassthrough: httpsPassthrough
|
||||
};
|
||||
|
||||
tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => {
|
||||
@ -107,7 +107,9 @@ tap.test('DomainManager - manage domain configurations', async () => {
|
||||
|
||||
// Add a domain configuration
|
||||
await domainManager.addDomainConfig(
|
||||
createDomainConfig('example.com', helpers.httpOnly('localhost', 3000))
|
||||
createDomainConfig('example.com', helpers.httpOnly({
|
||||
target: { host: 'localhost', port: 3000 }
|
||||
}))
|
||||
);
|
||||
|
||||
// Check that the configuration was added
|
||||
@ -132,13 +134,15 @@ tap.test('DomainManager - manage domain configurations', async () => {
|
||||
const handlerAfterRemoval = domainManager.findHandlerForDomain('example.com');
|
||||
expect(handlerAfterRemoval).toBeUndefined();
|
||||
});
|
||||
|
||||
|
||||
tap.test('DomainManager - support wildcard domains', async () => {
|
||||
const domainManager = new DomainManager();
|
||||
|
||||
// Add a wildcard domain configuration
|
||||
await domainManager.addDomainConfig(
|
||||
createDomainConfig('*.example.com', helpers.httpOnly('localhost', 3000))
|
||||
createDomainConfig('*.example.com', helpers.httpOnly({
|
||||
target: { host: 'localhost', port: 3000 }
|
||||
}))
|
||||
);
|
||||
|
||||
// Find a handler for a subdomain
|
||||
@ -150,15 +154,19 @@ tap.test('DomainManager - support wildcard domains', async () => {
|
||||
expect(noHandler).toBeUndefined();
|
||||
});
|
||||
tap.test('Helper Functions - create http-only forwarding config', async () => {
|
||||
const config = helpers.httpOnly('localhost', 3000);
|
||||
const config = helpers.httpOnly({
|
||||
target: { host: 'localhost', port: 3000 }
|
||||
});
|
||||
expect(config.type).toEqual('http-only');
|
||||
expect(config.target.host).toEqual('localhost');
|
||||
expect(config.target.port).toEqual(3000);
|
||||
expect(config.http?.enabled).toBeTrue();
|
||||
});
|
||||
|
||||
|
||||
tap.test('Helper Functions - create https-terminate-to-http config', async () => {
|
||||
const config = helpers.tlsTerminateToHttp('localhost', 3000);
|
||||
const config = helpers.tlsTerminateToHttp({
|
||||
target: { host: 'localhost', port: 3000 }
|
||||
});
|
||||
expect(config.type).toEqual('https-terminate-to-http');
|
||||
expect(config.target.host).toEqual('localhost');
|
||||
expect(config.target.port).toEqual(3000);
|
||||
@ -166,9 +174,11 @@ tap.test('Helper Functions - create https-terminate-to-http config', async () =>
|
||||
expect(config.acme?.enabled).toBeTrue();
|
||||
expect(config.acme?.maintenance).toBeTrue();
|
||||
});
|
||||
|
||||
|
||||
tap.test('Helper Functions - create https-terminate-to-https config', async () => {
|
||||
const config = helpers.tlsTerminateToHttps('localhost', 8443);
|
||||
const config = helpers.tlsTerminateToHttps({
|
||||
target: { host: 'localhost', port: 8443 }
|
||||
});
|
||||
expect(config.type).toEqual('https-terminate-to-https');
|
||||
expect(config.target.host).toEqual('localhost');
|
||||
expect(config.target.port).toEqual(8443);
|
||||
@ -176,9 +186,11 @@ tap.test('Helper Functions - create https-terminate-to-https config', async () =
|
||||
expect(config.acme?.enabled).toBeTrue();
|
||||
expect(config.acme?.maintenance).toBeTrue();
|
||||
});
|
||||
|
||||
|
||||
tap.test('Helper Functions - create https-passthrough config', async () => {
|
||||
const config = helpers.sniPassthrough('localhost', 443);
|
||||
const config = helpers.sniPassthrough({
|
||||
target: { host: 'localhost', port: 443 }
|
||||
});
|
||||
expect(config.type).toEqual('https-passthrough');
|
||||
expect(config.target.host).toEqual('localhost');
|
||||
expect(config.target.port).toEqual(443);
|
||||
|
Reference in New Issue
Block a user