BREAKING CHANGE(forwarding): Rename sniPassthrough export to httpsPassthrough for consistent naming and remove outdated forwarding example
This commit is contained in:
parent
a455ae1a64
commit
2482c8ae6b
@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# 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)
|
## 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.
|
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.
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ const helpers = {
|
|||||||
httpOnly,
|
httpOnly,
|
||||||
tlsTerminateToHttp,
|
tlsTerminateToHttp,
|
||||||
tlsTerminateToHttps,
|
tlsTerminateToHttps,
|
||||||
sniPassthrough: httpsPassthrough
|
httpsPassthrough
|
||||||
};
|
};
|
||||||
|
|
||||||
tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => {
|
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 () => {
|
tap.test('Helper Functions - create https-passthrough config', async () => {
|
||||||
const config = helpers.sniPassthrough({
|
const config = helpers.httpsPassthrough({
|
||||||
target: { host: 'localhost', port: 443 }
|
target: { host: 'localhost', port: 443 }
|
||||||
});
|
});
|
||||||
expect(config.type).toEqual('https-passthrough');
|
expect(config.type).toEqual('https-passthrough');
|
||||||
|
@ -12,7 +12,7 @@ const helpers = {
|
|||||||
httpOnly,
|
httpOnly,
|
||||||
tlsTerminateToHttp,
|
tlsTerminateToHttp,
|
||||||
tlsTerminateToHttps,
|
tlsTerminateToHttps,
|
||||||
sniPassthrough: httpsPassthrough
|
httpsPassthrough
|
||||||
};
|
};
|
||||||
|
|
||||||
tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => {
|
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 () => {
|
tap.test('Helper Functions - create https-passthrough config', async () => {
|
||||||
const config = helpers.sniPassthrough({
|
const config = helpers.httpsPassthrough({
|
||||||
target: { host: 'localhost', port: 443 }
|
target: { host: 'localhost', port: 443 }
|
||||||
});
|
});
|
||||||
expect(config.type).toEqual('https-passthrough');
|
expect(config.type).toEqual('https-passthrough');
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartproxy',
|
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.'
|
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.'
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
});
|
|
@ -48,5 +48,5 @@ export const helpers = {
|
|||||||
httpOnly,
|
httpOnly,
|
||||||
tlsTerminateToHttp,
|
tlsTerminateToHttp,
|
||||||
tlsTerminateToHttps,
|
tlsTerminateToHttps,
|
||||||
sniPassthrough: httpsPassthrough // Alias for backward compatibility
|
httpsPassthrough
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user