From 2482c8ae6bed402da23bb0458bb0561a31ff6ee3 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 9 May 2025 15:47:31 +0000 Subject: [PATCH] BREAKING CHANGE(forwarding): Rename sniPassthrough export to httpsPassthrough for consistent naming and remove outdated forwarding example --- changelog.md | 7 ++ test/test.forwarding.ts | 4 +- test/test.forwarding.unit.ts | 4 +- ts/00_commitinfo_data.ts | 2 +- ts/examples/forwarding-example.ts | 128 ------------------------------ ts/smartproxy/forwarding/index.ts | 2 +- 6 files changed, 13 insertions(+), 134 deletions(-) delete mode 100644 ts/examples/forwarding-example.ts diff --git a/changelog.md b/changelog.md index 9709708..6ceedce 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-05-09 - 12.0.0 - BREAKING CHANGE(forwarding) +Rename 'sniPassthrough' export to 'httpsPassthrough' for consistent naming and remove outdated forwarding example + +- Updated test files (test.forwarding.ts and test.forwarding.unit.ts) to reference 'httpsPassthrough' instead of the old alias 'sniPassthrough' +- Modified ts/smartproxy/forwarding/index.ts to export 'httpsPassthrough' without the legacy alias +- Removed ts/examples/forwarding-example.ts to clean up redundant example code + ## 2025-05-09 - 11.0.0 - 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. diff --git a/test/test.forwarding.ts b/test/test.forwarding.ts index 62b96de..12dcd54 100644 --- a/test/test.forwarding.ts +++ b/test/test.forwarding.ts @@ -12,7 +12,7 @@ const helpers = { httpOnly, tlsTerminateToHttp, tlsTerminateToHttps, - sniPassthrough: httpsPassthrough + httpsPassthrough }; tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => { @@ -188,7 +188,7 @@ tap.test('Helper Functions - create https-terminate-to-https config', async () = }); tap.test('Helper Functions - create https-passthrough config', async () => { - const config = helpers.sniPassthrough({ + const config = helpers.httpsPassthrough({ target: { host: 'localhost', port: 443 } }); expect(config.type).toEqual('https-passthrough'); diff --git a/test/test.forwarding.unit.ts b/test/test.forwarding.unit.ts index 644039a..bc1ee53 100644 --- a/test/test.forwarding.unit.ts +++ b/test/test.forwarding.unit.ts @@ -12,7 +12,7 @@ const helpers = { httpOnly, tlsTerminateToHttp, tlsTerminateToHttps, - sniPassthrough: httpsPassthrough + httpsPassthrough }; tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => { @@ -161,7 +161,7 @@ tap.test('Helper Functions - create https-terminate-to-https config', async () = }); tap.test('Helper Functions - create https-passthrough config', async () => { - const config = helpers.sniPassthrough({ + const config = helpers.httpsPassthrough({ target: { host: 'localhost', port: 443 } }); expect(config.type).toEqual('https-passthrough'); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 34a97c1..897d14e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartproxy', - version: '11.0.0', + version: '12.0.0', description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.' } diff --git a/ts/examples/forwarding-example.ts b/ts/examples/forwarding-example.ts deleted file mode 100644 index 5e8b6bf..0000000 --- a/ts/examples/forwarding-example.ts +++ /dev/null @@ -1,128 +0,0 @@ -import * as plugins from '../plugins.js'; -import { createServer } from 'http'; -import { Socket } from 'net'; -import { - DomainManager, - DomainManagerEvents, - createDomainConfig, - helpers -} from '../smartproxy/forwarding/index.js'; - -/** - * Example showing how to use the unified forwarding system - */ -async function main() { - console.log('Initializing forwarding example...'); - - // Create the domain manager - const domainManager = new DomainManager(); - - // Set up event listeners - domainManager.on(DomainManagerEvents.DOMAIN_ADDED, (data) => { - console.log(`Domain added: ${data.domains.join(', ')} (${data.forwardingType})`); - }); - - domainManager.on(DomainManagerEvents.DOMAIN_MATCHED, (data) => { - console.log(`Domain matched: ${data.domain} (${data.handlerType})`); - }); - - domainManager.on(DomainManagerEvents.DOMAIN_MATCH_FAILED, (data) => { - console.log(`Domain match failed: ${data.domain}`); - }); - - domainManager.on(DomainManagerEvents.ERROR, (data) => { - console.error(`Error:`, data); - }); - - // Add example domains with different forwarding types - - // Example 1: HTTP-only forwarding - await domainManager.addDomainConfig( - createDomainConfig('example.com', helpers.httpOnly({ - target: { host: 'localhost', port: 3000 } - })) - ); - - // Example 2: HTTPS termination with HTTP backend - await domainManager.addDomainConfig( - createDomainConfig('secure.example.com', helpers.tlsTerminateToHttp({ - target: { host: 'localhost', port: 3000 } - })) - ); - - // Example 3: HTTPS termination with HTTPS backend - await domainManager.addDomainConfig( - createDomainConfig('api.example.com', helpers.tlsTerminateToHttps({ - target: { host: 'localhost', port: 8443 } - })) - ); - - // Example 4: SNI passthrough - await domainManager.addDomainConfig( - createDomainConfig('passthrough.example.com', helpers.sniPassthrough({ - target: { host: '10.0.0.5', port: 443 } - })) - ); - - // Example 5: Custom configuration for a more complex setup - await domainManager.addDomainConfig( - createDomainConfig(['*.example.com', '*.example.org'], { - type: 'https-terminate-to-http', - target: { - host: ['10.0.0.10', '10.0.0.11'], // Round-robin load balancing - port: 8080 - }, - http: { - enabled: true, - redirectToHttps: false // Allow both HTTP and HTTPS - }, - acme: { - enabled: true, - maintenance: true, - production: false, // Use staging for testing - forwardChallenges: { - host: '192.168.1.100', - port: 8080 - } - }, - security: { - allowedIps: ['10.0.0.*', '192.168.1.*'], - maxConnections: 100 - }, - advanced: { - headers: { - 'X-Forwarded-For': '{clientIp}', - 'X-Forwarded-Host': '{sni}' - } - } - }) - ); - - // Create a simple HTTP server to demonstrate HTTP handler - const httpServer = createServer((req, res) => { - // Extract the domain from the Host header - const domain = req.headers.host?.split(':')[0] || 'unknown'; - - // Forward the request to the appropriate handler - if (!domainManager.handleHttpRequest(domain, req, res)) { - // No handler found, send a default response - res.statusCode = 404; - res.end(`No handler found for domain: ${domain}`); - } - }); - - // Listen on HTTP port - httpServer.listen(80, () => { - console.log('HTTP server listening on port 80'); - }); - - // For HTTPS and SNI, we would need to set up a TLS server - // This is a simplified example that just shows how the domain manager works - - console.log('Forwarding example initialized successfully'); -} - -// Run the example -main().catch(error => { - console.error('Error running example:', error); -}); \ No newline at end of file diff --git a/ts/smartproxy/forwarding/index.ts b/ts/smartproxy/forwarding/index.ts index 5dccef7..b8f39ee 100644 --- a/ts/smartproxy/forwarding/index.ts +++ b/ts/smartproxy/forwarding/index.ts @@ -48,5 +48,5 @@ export const helpers = { httpOnly, tlsTerminateToHttp, tlsTerminateToHttps, - sniPassthrough: httpsPassthrough // Alias for backward compatibility + httpsPassthrough }; \ No newline at end of file