BREAKING CHANGE(smart-proxy/utils/route-validator): Consolidate and refactor route validators; move to class-based API and update usages
Replaced legacy route-validators.ts with a unified route-validator.ts that provides a class-based RouteValidator plus the previous functional API (isValidPort, isValidDomain, validateRouteMatch, validateRouteAction, validateRouteConfig, validateRoutes, hasRequiredPropertiesForAction, assertValidRoute) for backwards compatibility. Updated utils exports and all imports/tests to reference the new module. Also switched static file loading in certificate manager to use SmartFileFactory.nodeFs(), and added @push.rocks/smartserve to devDependencies.
This commit is contained in:
@@ -109,17 +109,46 @@ export class HttpProxyBridge {
|
||||
if (!this.httpProxy) {
|
||||
throw new Error('HttpProxy not initialized');
|
||||
}
|
||||
|
||||
|
||||
// Check if client socket is already destroyed before proceeding
|
||||
const underlyingSocket = socket instanceof WrappedSocket ? socket.socket : socket;
|
||||
if (underlyingSocket.destroyed) {
|
||||
console.log(`[${connectionId}] Client socket already destroyed, skipping HttpProxy forwarding`);
|
||||
cleanupCallback('client_disconnected_before_proxy');
|
||||
return;
|
||||
}
|
||||
|
||||
const proxySocket = new plugins.net.Socket();
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
proxySocket.connect(httpProxyPort, 'localhost', () => {
|
||||
console.log(`[${connectionId}] Connected to HttpProxy for termination`);
|
||||
resolve();
|
||||
|
||||
// Handle client disconnect during proxy connection setup
|
||||
const clientDisconnectHandler = () => {
|
||||
console.log(`[${connectionId}] Client disconnected during HttpProxy connection setup`);
|
||||
proxySocket.destroy();
|
||||
cleanupCallback('client_disconnected_during_setup');
|
||||
};
|
||||
underlyingSocket.once('close', clientDisconnectHandler);
|
||||
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
proxySocket.connect(httpProxyPort, 'localhost', () => {
|
||||
console.log(`[${connectionId}] Connected to HttpProxy for termination`);
|
||||
resolve();
|
||||
});
|
||||
|
||||
proxySocket.on('error', reject);
|
||||
});
|
||||
|
||||
proxySocket.on('error', reject);
|
||||
});
|
||||
} finally {
|
||||
// Remove the disconnect handler after connection attempt
|
||||
underlyingSocket.removeListener('close', clientDisconnectHandler);
|
||||
}
|
||||
|
||||
// Double-check client socket is still connected after async operation
|
||||
if (underlyingSocket.destroyed) {
|
||||
console.log(`[${connectionId}] Client disconnected while connecting to HttpProxy`);
|
||||
proxySocket.destroy();
|
||||
cleanupCallback('client_disconnected_after_proxy_connect');
|
||||
return;
|
||||
}
|
||||
|
||||
// Send client IP information header first (custom protocol)
|
||||
// Format: "CLIENT_IP:<ip>\r\n"
|
||||
@@ -136,10 +165,7 @@ export class HttpProxyBridge {
|
||||
proxySocket.write(initialChunk);
|
||||
}
|
||||
|
||||
// Use centralized bidirectional forwarding
|
||||
// Extract underlying socket if it's a WrappedSocket
|
||||
const underlyingSocket = socket instanceof WrappedSocket ? socket.socket : socket;
|
||||
|
||||
// Use centralized bidirectional forwarding (underlyingSocket already extracted above)
|
||||
setupBidirectionalForwarding(underlyingSocket, proxySocket, {
|
||||
onClientData: (chunk) => {
|
||||
// Update stats - this is the ONLY place bytes are counted for HttpProxy connections
|
||||
|
||||
Reference in New Issue
Block a user