@serve.zone/remoteingress
Version:
Provides a service for creating private tunnels and reaching private clusters from the outside, facilitating secure remote access as part of the @serve.zone stack.
39 lines (32 loc) • 1.19 kB
text/typescript
import * as plugins from './plugins.js';
export class ConnectorPrivate {
private targetHost: string;
private targetPort: number;
constructor(targetHost: string, targetPort: number = 4000) {
this.targetHost = targetHost;
this.targetPort = targetPort;
this.connectToPublicRemoteConnector();
}
private connectToPublicRemoteConnector(): void {
const options = {
// Include CA certificate if necessary, for example:
// ca: fs.readFileSync('path/to/ca.pem'),
rejectUnauthorized: true // Only set this to true if you are sure about the server's certificate
};
const tunnel = plugins.tls.connect(this.targetPort, options, () => {
console.log('Connected to PublicRemoteConnector on port 4000');
});
tunnel.on('data', (data: Buffer) => {
const targetConnection = plugins.tls.connect({
host: this.targetHost,
port: this.targetPort,
// Include necessary options for the target connection
}, () => {
targetConnection.write(data);
});
targetConnection.on('data', (backData: Buffer) => {
tunnel.write(backData); // Send data back through the tunnel
});
});
}
}