fix(core): update

This commit is contained in:
2024-05-15 10:10:41 +02:00
commit cf500f9197
24 changed files with 7062 additions and 0 deletions

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: 'coretraffic',
version: '1.0.184',
description: 'route traffic within your docker setup. TypeScript ready.'
}

View File

@ -0,0 +1,43 @@
import * as plugins from './coretraffic.plugins.js';
import { logger } from './coretraffic.logging.js';
import { CoreTraffic } from './coretraffic.classes.coretraffic.js';
/**
* Coreflow Connector
*/
export class CoreflowConnector {
public typedrouter = new plugins.typedrequest.TypedRouter();
public coretrafficRef: CoreTraffic;
public typesocketClient: plugins.typedsocket.TypedSocket;
constructor(coretrafficRefArg: CoreTraffic) {
this.coretrafficRef = coretrafficRefArg;
this.coretrafficRef.typedrouter.addTypedRouter(this.typedrouter)
this.typedrouter.addTypedHandler<
plugins.lointCloudly.request.routing.IRequest_Coreflow_Coretraffic_RoutingUpdate
>(new plugins.typedrequest.TypedHandler('updateRouting', async (requestData) => {
console.log(requestData);
await this.coretrafficRef.taskmanager.setupRoutingTask.trigger(requestData.reverseConfigs);
return {
status: 'ok',
errorText: ''
};
}));
}
/**
* starts the corechatConnector
*/
public async start() {
this.typesocketClient = await plugins.typedsocket.TypedSocket.createClient(
this.typedrouter,
'http://coreflow:3000',
'coretraffic'
);
}
public async stop() {
await this.typesocketClient.stop();
}
}

View File

@ -0,0 +1,55 @@
import * as plugins from './coretraffic.plugins.js';
import * as paths from './coretraffic.paths.js'
import { logger } from './coretraffic.logging.js';
import { CoreflowConnector } from './coretraffic.classes.coreflowconnector.js';
import { CoretrafficTaskManager } from './coretraffic.classes.taskmanager.js';
export interface ICoretrafficConfig {
dockerDomainEnvName?: string;
}
export class CoreTraffic {
public projectinfo = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
public typedrouter = new plugins.typedrequest.TypedRouter();
public coreflowConnector: CoreflowConnector;
public taskmanager: CoretrafficTaskManager;
public networkProxy: plugins.smartproxy.NetworkProxy;
public sslRedirect: plugins.smartproxy.SslRedirect;
constructor() {
this.coreflowConnector = new CoreflowConnector(this);
this.taskmanager = new CoretrafficTaskManager(this);
this.networkProxy = new plugins.smartproxy.NetworkProxy({
port: 8000
});
this.sslRedirect = new plugins.smartproxy.SslRedirect(7999);
}
/**
* starts coretraffic
*/
public async start() {
await this.networkProxy.start();
await this.sslRedirect.start();
this.networkProxy.addDefaultHeaders({
servezone_coretraffic_version: this.projectinfo.version
})
await this.taskmanager.start();
await this.coreflowConnector.start();
}
/**
* stops coretraffic
*/
public async stop() {
await this.taskmanager.stop();
console.log('stopped taskmanager');
await this.coreflowConnector.stop();
console.log('stopped coreflowConnector');
await this.networkProxy.stop();
console.log('stopped smartproxy!');
await this.sslRedirect.stop();
}
}

View File

@ -0,0 +1,35 @@
import * as plugins from './coretraffic.plugins.js';
import { CoreTraffic } from './coretraffic.classes.coretraffic.js';
import { logger } from './coretraffic.logging.js';
export class CoretrafficTaskManager {
public coretrafficRef: CoreTraffic;
public taskmanager: plugins.taskbuffer.TaskManager;
/**
* a task to run setup routing, runs buffered
*/
public setupRoutingTask: plugins.taskbuffer.Task;
constructor(coretrafficRefArg: CoreTraffic) {
this.coretrafficRef = coretrafficRefArg;
this.taskmanager = new plugins.taskbuffer.TaskManager();
this.setupRoutingTask = new plugins.taskbuffer.Task({
buffered: true,
bufferMax: 2,
taskFunction: async (reverseConfigs: plugins.lointCloudly.traffic.IReverseProxyConfig[]) => {
console.log('this is what got to the task:');
console.log(reverseConfigs);
logger.log('info', `routing setup task triggered`);
logger.log('info', `Found ${reverseConfigs.length} host reverse configs!`);
logger.log('info', `trying to deploy host candidates now`);
await this.coretrafficRef.networkProxy.updateProxyConfigs(reverseConfigs);
},
});
}
public async start() {}
public async stop() {}
}

14
ts/coretraffic.logging.ts Normal file
View File

@ -0,0 +1,14 @@
import * as plugins from './coretraffic.plugins.js';
import * as paths from './coretraffic.paths.js';
const projectInfoNpm = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
export const logger = new plugins.smartlog.Smartlog({
logContext: {
environment: 'production',
runtime: 'node',
zone: 'serve.zone',
containerName: 'coretraffic',
},
minimumLogLevel: 'info',
});

6
ts/coretraffic.paths.ts Normal file
View File

@ -0,0 +1,6 @@
import * as plugins from './coretraffic.plugins.js';
// Directories
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
export const appSslDir = '/app_certs';
export const nginxConfDir = '/etc/nginx/conf.d/';

44
ts/coretraffic.plugins.ts Normal file
View File

@ -0,0 +1,44 @@
// NODE INTERNALS
import * as path from 'path';
export { path };
// @serve.zone scope
import * as lointCloudly from '@losslessone_private/loint-cloudly';
export { lointCloudly };
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
import * as typedsocket from '@api.global/typedsocket';
export { typedrequest, typedsocket };
// @push.rocks scope
import * as qenv from '@push.rocks/qenv';
import * as projectinfo from '@push.rocks/projectinfo';
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationReceiver from '@push.rocks/smartlog-destination-receiver';
import * as smartpath from '@push.rocks/smartpath';
import * as smartproxy from '@push.rocks/smartproxy';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrequest from '@push.rocks/smartrequest';
import * as smartshell from '@push.rocks/smartshell';
import * as smartstring from '@push.rocks/smartstring';
import * as taskbuffer from '@push.rocks/taskbuffer';
export {
qenv,
projectinfo,
smartdelay,
smartlog,
smartlogDestinationReceiver,
smartpath,
smartproxy,
smartshell,
smartpromise,
smartrequest,
smartstring,
taskbuffer,
};

22
ts/index.ts Normal file
View File

@ -0,0 +1,22 @@
console.log('**** Starting coretraffic ****');
import * as plugins from './coretraffic.plugins.js';
import * as paths from './coretraffic.paths.js';
import { logger } from './coretraffic.logging.js';
import { CoreTraffic } from './coretraffic.classes.coretraffic.js';
export { CoreTraffic };
const projectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
let coretrafficInstance: CoreTraffic;
export const runCli = async () => {
logger.log('info', `coretraffic@v${projectinfo.npm.version}`);
coretrafficInstance = new CoreTraffic();
await coretrafficInstance.start();
logger.log('info', 'coretraffic successfully started!');
};
export const stop = async () => {
coretrafficInstance.stop();
};