fix(core): update

This commit is contained in:
2024-04-14 03:38:00 +02:00
parent eecc510a49
commit 6d14056cfd
16 changed files with 267 additions and 196 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/remoteingress',
version: '1.0.2',
description: 'a remoteingress service for serve.zone'
version: '1.0.3',
description: 'Provides a service for creating private tunnels and reaching private clusters from the outside as part of the @serve.zone stack.'
}

View File

@ -1,10 +1,10 @@
import * as tls from 'tls';
import * as plugins from './plugins.js';
export class ConnectorPrivate {
private targetHost: string;
private targetPort: number;
constructor(targetHost: string, targetPort: number) {
constructor(targetHost: string, targetPort: number = 4000) {
this.targetHost = targetHost;
this.targetPort = targetPort;
this.connectToPublicRemoteConnector();
@ -12,15 +12,27 @@ export class ConnectorPrivate {
private connectToPublicRemoteConnector(): void {
const options = {
// If your server requires client certificate authentication, you can specify key and cert here as well
// 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 = tls.connect({ port: 4000, ...options }, () => {
const tunnel = plugins.tls.connect(this.targetPort, options, () => {
console.log('Connected to PublicRemoteConnector on port 4000');
});
tunnel.on('data', (data: Buffer) => {
// Similar logic for forwarding data to and from the target
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
});
});
}
}

View File

@ -1,8 +1,7 @@
import * as tls from 'tls';
import * as fs from 'fs';
import * as plugins from './plugins.js';
export class ConnectorPublic {
private tunnel: tls.TLSSocket | null = null;
class PublicRemoteConnector {
private tunnel: plugins.tls.TLSSocket | null = null;
constructor() {
this.createTunnel();
@ -11,11 +10,11 @@ export class ConnectorPublic {
private createTunnel(): void {
const options = {
key: fs.readFileSync('path/to/key.pem'),
cert: fs.readFileSync('path/to/cert.pem')
key: plugins.fs.readFileSync('path/to/key.pem'),
cert: plugins.fs.readFileSync('path/to/cert.pem'),
};
const server = tls.createServer(options, (socket: tls.TLSSocket) => {
const server = plugins.tls.createServer(options, (socket: plugins.tls.TLSSocket) => {
this.tunnel = socket;
console.log('Tunnel established with LocalConnector');
});
@ -26,7 +25,21 @@ export class ConnectorPublic {
}
private listenOnPorts(): void {
// Implement similar logic for listening on ports 80 and 443
// Keep in mind you may need to adjust how you handle secure and non-secure traffic
// Example for port 80, adapt for port 443 similarly
// Note: TLS for the initial connection might not apply directly for HTTP/HTTPS traffic without additional setup
const options = {
key: plugins.fs.readFileSync('path/to/key.pem'),
cert: plugins.fs.readFileSync('path/to/cert.pem'),
};
plugins.tls.createServer(options, (socket: plugins.tls.TLSSocket) => {
console.log('Received connection, tunneling to LocalConnector');
if (this.tunnel) {
socket.pipe(this.tunnel).pipe(socket);
} else {
console.log('Tunnel to LocalConnector not established');
socket.end();
}
}).listen(80); // Repeat this block for any other ports you wish to listen on
}
}

View File

@ -1,3 +1,14 @@
import * as plugins from './remoteingress.plugins.js';
import * as plugins from './plugins.js';
export let demoExport = 'Hi there! :) This is an exported string';
import { ConnectorPublic } from './connector.public.js';
import { ConnectorPrivate } from './connector.private.js';
export {
ConnectorPublic,
ConnectorPrivate
}
export const runCli = async () => {
const qenv = new plugins.qenv.Qenv();
const mode = await qenv.getEnvVarOnDemand('MODE');
}

15
ts/plugins.ts Normal file
View File

@ -0,0 +1,15 @@
// node native scope
import * as tls from 'tls';
import * as fs from 'fs';
export {
tls,
fs,
}
// @push.rocks scope
import * as qenv from '@push.rocks/qenv';
export {
qenv,
}

View File

@ -1,4 +0,0 @@
const removeme = {};
export {
removeme
}