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:
2025-05-09 15:39:15 +00:00
parent f00bae4631
commit 1a902a04fb
20 changed files with 441 additions and 434 deletions

View File

@ -6,13 +6,13 @@ import type { IForwardConfig } from '../ts/smartproxy/types/forwarding.types.js'
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
@ -125,15 +127,19 @@ tap.test('DomainManager - manage domain configurations', async () => {
expect(configsAfterRemoval.length).toEqual(0);
});
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);
@ -141,9 +147,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);
@ -151,9 +159,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);