refactor: migrate coretraffic to current smartproxy
This commit is contained in:
@@ -1,20 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmdocker": {
|
"@ship.zone/szci": {
|
||||||
"baseImage": "host.today/ht-docker-node:npmci",
|
|
||||||
"command": "echo \"inside docker now\"",
|
|
||||||
"dockerSock": true
|
|
||||||
},
|
|
||||||
"npmci": {
|
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmRegistryUrl": "verdaccio.lossless.one",
|
"npmRegistryUrl": "verdaccio.lossless.one"
|
||||||
"dockerRegistryRepoMap": {
|
},
|
||||||
|
"@git.zone/tsdocker": {
|
||||||
|
"registryRepoMap": {
|
||||||
"registry.gitlab.com": "losslessone/services/servezone/coretraffic"
|
"registry.gitlab.com": "losslessone/services/servezone/coretraffic"
|
||||||
},
|
},
|
||||||
"dockerBuildargEnvMap": {
|
"buildArgEnvMap": {
|
||||||
"NPMCI_TOKEN_NPM2": "NPMCI_TOKEN_NPM2"
|
"SZCI_TOKEN_NPM2": "SZCI_TOKEN_NPM2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"@git.zone/cli": {
|
||||||
"projectType": "service",
|
"projectType": "service",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
+13
-13
@@ -1,40 +1,40 @@
|
|||||||
# gitzone dockerfile_service
|
# gitzone dockerfile_service
|
||||||
## STAGE 1 // BUILD
|
## STAGE 1 // BUILD
|
||||||
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci as node1
|
FROM code.foss.global/host.today/ht-docker-node:szci as node1
|
||||||
COPY ./ /app
|
COPY ./ /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ARG NPMCI_TOKEN_NPM2
|
ARG SZCI_TOKEN_NPM2
|
||||||
ENV NPMCI_TOKEN_NPM2 $NPMCI_TOKEN_NPM2
|
ENV SZCI_TOKEN_NPM2 $SZCI_TOKEN_NPM2
|
||||||
RUN npmci npm prepare
|
RUN szci npm prepare
|
||||||
RUN pnpm config set store-dir .pnpm-store
|
RUN pnpm config set store-dir .pnpm-store
|
||||||
RUN rm -rf node_modules && pnpm install
|
RUN rm -rf node_modules && pnpm install
|
||||||
RUN pnpm run build
|
RUN pnpm run build
|
||||||
|
|
||||||
# gitzone dockerfile_service
|
# gitzone dockerfile_service
|
||||||
## STAGE 2 // install production
|
## STAGE 2 // install production
|
||||||
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci as node2
|
FROM code.foss.global/host.today/ht-docker-node:szci as node2
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=node1 /app /app
|
COPY --from=node1 /app /app
|
||||||
RUN rm -rf .pnpm-store
|
RUN rm -rf .pnpm-store
|
||||||
ARG NPMCI_TOKEN_NPM2
|
ARG SZCI_TOKEN_NPM2
|
||||||
ENV NPMCI_TOKEN_NPM2 $NPMCI_TOKEN_NPM2
|
ENV SZCI_TOKEN_NPM2 $SZCI_TOKEN_NPM2
|
||||||
RUN npmci npm prepare
|
RUN szci npm prepare
|
||||||
RUN pnpm config set store-dir .pnpm-store
|
RUN pnpm config set store-dir .pnpm-store
|
||||||
RUN rm -rf node_modules/ && pnpm install --prod
|
RUN rm -rf node_modules/ && pnpm install --prod
|
||||||
|
|
||||||
|
|
||||||
## STAGE 3 // rebuild dependencies for alpine
|
## STAGE 3 // rebuild dependencies for alpine
|
||||||
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpinenpmci as node3
|
FROM code.foss.global/host.today/ht-docker-node:alpine-szci as node3
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=node2 /app /app
|
COPY --from=node2 /app /app
|
||||||
ARG NPMCI_TOKEN_NPM2
|
ARG SZCI_TOKEN_NPM2
|
||||||
ENV NPMCI_TOKEN_NPM2 $NPMCI_TOKEN_NPM2
|
ENV SZCI_TOKEN_NPM2 $SZCI_TOKEN_NPM2
|
||||||
RUN npmci npm prepare
|
RUN szci npm prepare
|
||||||
RUN pnpm config set store-dir .pnpm-store
|
RUN pnpm config set store-dir .pnpm-store
|
||||||
RUN pnpm rebuild -r
|
RUN pnpm rebuild -r
|
||||||
|
|
||||||
## STAGE 4 // the final production image with all dependencies in place
|
## STAGE 4 // the final production image with all dependencies in place
|
||||||
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine as node4
|
FROM code.foss.global/host.today/ht-docker-node:alpine-node as node4
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=node3 /app /app
|
COPY --from=node3 /app /app
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Task Venture Capital GmbH
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+19
-25
@@ -9,7 +9,7 @@
|
|||||||
"start": "node --max_old_space_size=1000 cli.js",
|
"start": "node --max_old_space_size=1000 cli.js",
|
||||||
"startTs": "node cli.ts.js",
|
"startTs": "node cli.ts.js",
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web --allowimplicitany)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -26,36 +26,35 @@
|
|||||||
"real-time updates",
|
"real-time updates",
|
||||||
"task management"
|
"task management"
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Task Venture Capital GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/servezone/coretraffic/issues"
|
"url": "https://gitlab.com/servezone/coretraffic/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/servezone/coretraffic#README",
|
"homepage": "https://gitlab.com/servezone/coretraffic#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@api.global/typedrequest": "^3.1.10",
|
"@api.global/typedrequest": "^3.3.0",
|
||||||
"@api.global/typedsocket": "^3.0.1",
|
"@api.global/typedsocket": "^4.1.2",
|
||||||
"@push.rocks/projectinfo": "^5.0.1",
|
"@push.rocks/projectinfo": "^5.1.0",
|
||||||
"@push.rocks/qenv": "^6.1.0",
|
"@push.rocks/qenv": "^6.1.3",
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@push.rocks/smartlog": "^3.0.7",
|
"@push.rocks/smartlog": "^3.0.7",
|
||||||
"@push.rocks/smartlog-destination-receiver": "^2.0.3",
|
"@push.rocks/smartlog-destination-receiver": "^2.0.3",
|
||||||
"@push.rocks/smartpath": "^5.0.5",
|
"@push.rocks/smartpath": "^6.0.0",
|
||||||
"@push.rocks/smartpromise": "^4.0.4",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@push.rocks/smartproxy": "^3.1.0",
|
"@push.rocks/smartproxy": "^27.9.0",
|
||||||
"@push.rocks/smartrequest": "^2.0.23",
|
"@push.rocks/smartrequest": "^5.0.1",
|
||||||
"@push.rocks/smartshell": "^3.2.2",
|
"@push.rocks/smartshell": "^3.3.8",
|
||||||
"@push.rocks/smartstring": "^4.0.2",
|
"@push.rocks/smartstring": "^4.0.2",
|
||||||
"@push.rocks/taskbuffer": "^3.0.10",
|
"@push.rocks/taskbuffer": "^8.0.2",
|
||||||
"@serve.zone/interfaces": "^5.4.3",
|
"@serve.zone/interfaces": "^5.4.4",
|
||||||
"@tsclass/tsclass": "^4.2.0"
|
"@tsclass/tsclass": "^9.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.2.0",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@git.zone/tsrun": "^1.3.3",
|
"@git.zone/tsrun": "^2.0.2",
|
||||||
"@git.zone/tstest": "^1.0.74",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@push.rocks/tapbundle": "^5.5.3",
|
"@types/node": "^25.6.0"
|
||||||
"@types/node": "^22.10.2"
|
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"files": [
|
"files": [
|
||||||
@@ -67,15 +66,10 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
".smartconfig.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
],
|
]
|
||||||
"pnpm": {
|
|
||||||
"overrides": {
|
|
||||||
"glob@10.3.12>path-scurry": "1.11.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+4160
-3259
File diff suppressed because it is too large
Load Diff
@@ -1,224 +1,121 @@
|
|||||||
# CoreTraffic
|
# CoreTraffic
|
||||||
|
|
||||||
route traffic within your docker setup. TypeScript ready.
|
CoreTraffic is the serve.zone ingress component that receives routing updates from Coreflow and applies them to `@push.rocks/smartproxy`. It runs as a small TypeScript service inside the cluster and keeps HTTP redirects, HTTPS termination, backend routing, default response headers, and optional basic authentication in sync with the control plane.
|
||||||
|
|
||||||
## Install
|
## Issue Reporting and Security
|
||||||
|
|
||||||
To install `coretraffic`, you should have Node.js already set up on your system. Assuming Node.js and npm are ready, install the package via the npm registry with the following command:
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
|
|
||||||
```bash
|
## What It Does
|
||||||
npm install coretraffic
|
|
||||||
|
CoreTraffic is intentionally focused:
|
||||||
|
|
||||||
|
- Starts a `SmartProxy` instance for cluster ingress.
|
||||||
|
- Connects to Coreflow over `@api.global/typedsocket`.
|
||||||
|
- Registers the `updateRouting` typed request handler.
|
||||||
|
- Converts `IReverseProxyConfig[]` updates into SmartProxy route configs.
|
||||||
|
- Adds an HTTP-to-HTTPS redirect route on port `7999`.
|
||||||
|
- Adds HTTPS reverse-proxy routes on port `8000` with per-domain certificates.
|
||||||
|
- Adds the `servezone_coretraffic_version` response header to managed routes.
|
||||||
|
|
||||||
|
## Runtime Flow
|
||||||
|
|
||||||
|
```text
|
||||||
|
Coreflow
|
||||||
|
-> TypedSocket updateRouting
|
||||||
|
-> CoreflowConnector
|
||||||
|
-> CoretrafficTaskManager buffered setupRouting task
|
||||||
|
-> SmartProxy.updateRoutes(...)
|
||||||
```
|
```
|
||||||
|
|
||||||
To make the most out of `coretraffic`, ensure TypeScript is set up in your development environment, as this module is TypeScript ready and provides enhanced IntelliSense.
|
Routing updates are buffered so fast repeated changes collapse into the most recent route state instead of overwhelming the proxy engine.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
`coretraffic` is designed to manage and route traffic within a Docker setup, offering robust solutions to your traffic management needs with an emphasis on efficiency and reliability. Utilizing TypeScript for static typing, you get enhanced code completion and fewer runtime errors. The module is set up to handle the intricacies of proxy configuration and routing, providing a powerful foundation for any Docker-based traffic management application.
|
|
||||||
|
|
||||||
Below, we'll delve into the capabilities and features of `coretraffic`, complete with comprehensive examples to get you started.
|
|
||||||
|
|
||||||
### Initializing CoreTraffic
|
|
||||||
|
|
||||||
First, you'll want to create an instance of the `CoreTraffic` class. This serves as the entry point to accessing the module's capabilities.
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { CoreTraffic } from 'coretraffic';
|
import { CoreTraffic } from 'coretraffic';
|
||||||
|
|
||||||
// Create an instance of CoreTraffic
|
const coreTraffic = new CoreTraffic();
|
||||||
const coreTrafficInstance = new CoreTraffic();
|
await coreTraffic.start();
|
||||||
|
|
||||||
|
// later
|
||||||
|
await coreTraffic.stop();
|
||||||
```
|
```
|
||||||
|
|
||||||
This initializes the `coreTrafficInstance` with default properties, ready to configure routing settings and handle proxy configurations.
|
In production, CoreTraffic is normally started through `runCli()` and expects Coreflow to be reachable at `http://coreflow:3000`.
|
||||||
|
|
||||||
### Starting and Stopping CoreTraffic
|
## Routing Input
|
||||||
|
|
||||||
Controlling the lifecycle of your `CoreTraffic` instance is key to effective traffic management. You can start and stop the instance with straightforward method calls.
|
CoreTraffic consumes `@tsclass/tsclass` reverse proxy configs:
|
||||||
|
|
||||||
#### Starting CoreTraffic
|
|
||||||
|
|
||||||
To begin managing traffic, start the instance. This sets up the internal network proxy and SSL redirection services, making them ready to handle incoming requests.
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
async function startCoreTraffic() {
|
const reverseConfig = {
|
||||||
await coreTrafficInstance.start();
|
hostName: 'app.example.com',
|
||||||
console.log('CoreTraffic is now running.');
|
destinationIps: ['10.0.0.10'],
|
||||||
}
|
destinationPorts: [3000],
|
||||||
|
privateKey: '-----BEGIN PRIVATE KEY-----...',
|
||||||
startCoreTraffic();
|
publicKey: '-----BEGIN CERTIFICATE-----...',
|
||||||
```
|
authentication: {
|
||||||
|
type: 'Basic',
|
||||||
This code initializes all internal components, including `NetworkProxy` and `SslRedirect`, beginning to route traffic as configured.
|
user: 'admin',
|
||||||
|
pass: 'secret',
|
||||||
#### Stopping CoreTraffic
|
},
|
||||||
|
|
||||||
When you no longer need to route traffic, shutting down the instance cleanly is important. `CoreTraffic` provides a `stop` method for this purpose.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
async function stopCoreTraffic() {
|
|
||||||
await coreTrafficInstance.stop();
|
|
||||||
console.log('CoreTraffic has stopped.');
|
|
||||||
}
|
|
||||||
|
|
||||||
stopCoreTraffic();
|
|
||||||
```
|
|
||||||
|
|
||||||
This ensures all background tasks are halted, and network configurations are cleaned up.
|
|
||||||
|
|
||||||
### Configuring Network Proxy
|
|
||||||
|
|
||||||
A core feature of `CoreTraffic` is its ability to configure network proxies dynamically. At its heart is the `NetworkProxy` class, a powerful tool for managing routing configurations.
|
|
||||||
|
|
||||||
#### Adding Default Headers
|
|
||||||
|
|
||||||
You may wish to integrate unique headers across all routed requests, possible with the `addDefaultHeaders` method. This is useful for tagging requests or managing CORS.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
coreTrafficInstance.networkProxy.addDefaultHeaders({
|
|
||||||
'x-powered-by': 'coretraffic',
|
|
||||||
'custom-header': 'custom-value'
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
This injects custom headers into all outgoing responses managed by `coretraffic`, thereby allowing customized interaction with requests as needed.
|
|
||||||
|
|
||||||
#### Proxy Configuration Updates
|
|
||||||
|
|
||||||
Dynamic updates to proxy configurations can be facilitated via tasks managed by `CoretrafficTaskManager`. This feature allows adjustment of routing rules without interrupting service.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { IReverseProxyConfig } from '@tsclass/network';
|
|
||||||
|
|
||||||
const configureRouting = async () => {
|
|
||||||
const reverseProxyConfig: IReverseProxyConfig[] = [{
|
|
||||||
// Example configuration, adjust as needed
|
|
||||||
host: 'example.com',
|
|
||||||
target: 'http://internal-service:3000',
|
|
||||||
}];
|
|
||||||
|
|
||||||
await coreTrafficInstance.taskmanager.setupRoutingTask.trigger(reverseProxyConfig);
|
|
||||||
console.log('Updated routing configurations');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
configureRouting();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, a reverse proxy configuration is defined, specifying that requests to `example.com` should be directed to an internal service.
|
Each config becomes one HTTPS SmartProxy route with TLS termination and one or more backend targets generated from the destination IP/port combinations.
|
||||||
|
|
||||||
### SSL Redirection
|
## Development
|
||||||
|
|
||||||
`CoreTraffic` supports SSL redirection, an essential feature for secure communications. The `SslRedirect` component listens on one port to redirect traffic to the secure version on another port.
|
Install dependencies with pnpm:
|
||||||
|
|
||||||
```typescript
|
```bash
|
||||||
// SslRedirect is initialized on port 7999 by default
|
pnpm install
|
||||||
console.log('SSL Redirection is active!');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Out-of-the-box, this listens on the configurable port and safely forwards insecure HTTP traffic to its HTTPS counterpart.
|
Build TypeScript:
|
||||||
|
|
||||||
### Coreflow Connector
|
```bash
|
||||||
|
pnpm run build
|
||||||
A unique aspect of `coretraffic` is its integration capability with `Coreflow`, allowing communication between different network nodes. The `CoreflowConnector` facilitates receiving configuration updates via a socket connection.
|
|
||||||
|
|
||||||
#### Setting up the CoreflowConnector
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const coreflowConnector = coreTrafficInstance.coreflowConnector;
|
|
||||||
|
|
||||||
async function connectCoreflow() {
|
|
||||||
await coreflowConnector.start();
|
|
||||||
console.log('Coreflow connector activated.');
|
|
||||||
}
|
|
||||||
|
|
||||||
connectCoreflow();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This method enables a persistent connection to a Coreflow server, allowing real-time configuration updates and management of routing policies.
|
Run tests:
|
||||||
|
|
||||||
#### Stopping the CoreflowConnector
|
```bash
|
||||||
|
pnpm test
|
||||||
To disconnect cleanly:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
async function disconnectCoreflow() {
|
|
||||||
await coreflowConnector.stop();
|
|
||||||
console.log('Coreflow connector terminated.');
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnectCoreflow();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This halts the connection, ensuring no dangling resources remain when shutting down your application.
|
Check outdated dependencies:
|
||||||
|
|
||||||
### Task Management
|
```bash
|
||||||
|
pnpm outdated
|
||||||
The `CoretrafficTaskManager` handles complex, buffered tasks. Flexibility and power are at your fingertips with this system, ideal for timed or queued execution needs.
|
|
||||||
|
|
||||||
#### Managing Tasks
|
|
||||||
|
|
||||||
Here is how you would initiate the task manager:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
const taskManager = coreTrafficInstance.taskmanager;
|
|
||||||
|
|
||||||
// Start tasks
|
|
||||||
taskManager.start()
|
|
||||||
.then(() => console.log('Task manager is running'))
|
|
||||||
.catch(err => console.error('Failed to start task manager', err));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Stop tasks once processing is no longer required:
|
## Important Dependencies
|
||||||
|
|
||||||
```typescript
|
- `@push.rocks/smartproxy`: route-based proxy engine used for redirects, TLS termination, and forwarding.
|
||||||
taskManager.stop()
|
- `@api.global/typedsocket`: Coreflow connection transport.
|
||||||
.then(() => console.log('Task manager stopped'))
|
- `@api.global/typedrequest`: typed RPC handler registration.
|
||||||
.catch(err => console.error('Failed to stop task manager', err));
|
- `@serve.zone/interfaces`: typed Coreflow/CoreTraffic routing request contract.
|
||||||
```
|
- `@push.rocks/taskbuffer`: buffered routing update execution.
|
||||||
|
|
||||||
### Logging and Debugging
|
## License and Legal Information
|
||||||
|
|
||||||
Effective logging is provided using `Smartlog`, designed to track detailed application insights and report on activity and actions within `coretraffic`.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license) file.
|
||||||
|
|
||||||
#### Configuring Log Levels
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
`coretraffic` supports log levels which can be adjusted as per your requirements:
|
### Trademarks
|
||||||
|
|
||||||
```typescript
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||||
import { logger } from './coretraffic.logging.ts';
|
|
||||||
|
|
||||||
logger.log('info', 'System initialized');
|
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
logger.log('debug', 'Detailed debugging process');
|
|
||||||
logger.log('warn', 'Potential issue detected');
|
|
||||||
logger.log('error', 'An error has occurred');
|
|
||||||
```
|
|
||||||
|
|
||||||
These log entries help monitor logic flow and catch issues during development or deployment in production environments.
|
### Company Information
|
||||||
|
|
||||||
### Test Setup
|
Task Venture Capital GmbH
|
||||||
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
For those interested in testing, `coretraffic` uses `tapbundle` and `tstest` to ensure reliability and correctness. A sample test module is provided to demonstrate initialization and lifecycle actions.
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
Here’s an example of a non-CI test scenario:
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
|
||||||
```typescript
|
|
||||||
import * as coretraffic from '../ts/index.js';
|
|
||||||
import { tap, expect } from '@push.rocks/tapbundle';
|
|
||||||
|
|
||||||
let testCoreTraffic;
|
|
||||||
|
|
||||||
tap.test('should create and handle coretraffic instances', async () => {
|
|
||||||
testCoreTraffic = new coretraffic.CoreTraffic();
|
|
||||||
expect(testCoreTraffic).toBeInstanceOf(coretraffic.CoreTraffic);
|
|
||||||
|
|
||||||
await testCoreTraffic.start();
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 10000)); // Keep alive for demonstration
|
|
||||||
await testCoreTraffic.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
```
|
|
||||||
|
|
||||||
This test suite validates essential functionality within development iterations, ensuring `coretraffic` performs as expected.
|
|
||||||
|
|
||||||
`coretraffic` offers a vast landscape of operations within Docker environments, handling traffic with modularity and efficiency. Whether starting simple routing tasks or integrating with complex systems like Coreflow, this module provides robust support where needed most. Embrace your traffic management challenges with the dedicated features of `coretraffic`.
|
|
||||||
undefined
|
|
||||||
|
|||||||
+6
-2
@@ -1,11 +1,12 @@
|
|||||||
delete process.env.CLI_CALL;
|
delete process.env.CLI_CALL;
|
||||||
import * as coretraffic from '../ts/index.js';
|
import * as coretraffic from '../ts/index.js';
|
||||||
|
|
||||||
import { tap, expect } from '@push.rocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
import { Qenv } from '@push.rocks/qenv';
|
import { Qenv } from '@push.rocks/qenv';
|
||||||
|
|
||||||
const testQenv = new Qenv('./', './.nogit');
|
const testQenv = new Qenv('./', './.nogit');
|
||||||
let testCoreTraffic: coretraffic.CoreTraffic;
|
let testCoreTraffic: coretraffic.CoreTraffic;
|
||||||
|
const shouldRunIntegrationTests = process.env.CORETRAFFIC_INTEGRATION_TESTS === 'true';
|
||||||
|
|
||||||
tap.test('should create an coretraffic instance', async (tools) => {
|
tap.test('should create an coretraffic instance', async (tools) => {
|
||||||
testCoreTraffic = new coretraffic.CoreTraffic();
|
testCoreTraffic = new coretraffic.CoreTraffic();
|
||||||
@@ -13,15 +14,18 @@ tap.test('should create an coretraffic instance', async (tools) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start the instance', async (tools) => {
|
tap.test('should start the instance', async (tools) => {
|
||||||
|
tools.skipIf(!shouldRunIntegrationTests, 'set CORETRAFFIC_INTEGRATION_TESTS=true to start CoreTraffic');
|
||||||
await testCoreTraffic.start();
|
await testCoreTraffic.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should keep the instance alive', async (tools) => {
|
tap.test('should keep the instance alive', async (tools) => {
|
||||||
|
tools.skipIf(!shouldRunIntegrationTests, 'set CORETRAFFIC_INTEGRATION_TESTS=true to keep CoreTraffic alive');
|
||||||
await tools.delayFor(10000);
|
await tools.delayFor(10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop the instance', async (tools) => {
|
tap.test('should stop the instance', async (tools) => {
|
||||||
|
tools.skipIf(!shouldRunIntegrationTests, 'set CORETRAFFIC_INTEGRATION_TESTS=true to stop CoreTraffic');
|
||||||
await testCoreTraffic.stop();
|
await testCoreTraffic.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import { CoreTraffic } from './coretraffic.classes.coretraffic.js';
|
|||||||
* Coreflow Connector
|
* Coreflow Connector
|
||||||
*/
|
*/
|
||||||
export class CoreflowConnector {
|
export class CoreflowConnector {
|
||||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
public typedrouter: plugins.typedrequest.TypedRouter = new plugins.typedrequest.TypedRouter();
|
||||||
public coretrafficRef: CoreTraffic;
|
public coretrafficRef: CoreTraffic;
|
||||||
public typesocketClient: plugins.typedsocket.TypedSocket;
|
public typesocketClient!: plugins.typedsocket.TypedSocket;
|
||||||
|
|
||||||
constructor(coretrafficRefArg: CoreTraffic) {
|
constructor(coretrafficRefArg: CoreTraffic) {
|
||||||
this.coretrafficRef = coretrafficRefArg;
|
this.coretrafficRef = coretrafficRefArg;
|
||||||
@@ -32,9 +32,9 @@ export class CoreflowConnector {
|
|||||||
public async start() {
|
public async start() {
|
||||||
this.typesocketClient = await plugins.typedsocket.TypedSocket.createClient(
|
this.typesocketClient = await plugins.typedsocket.TypedSocket.createClient(
|
||||||
this.typedrouter,
|
this.typedrouter,
|
||||||
'http://coreflow:3000',
|
'http://coreflow:3000'
|
||||||
'coretraffic'
|
|
||||||
);
|
);
|
||||||
|
await this.typesocketClient.setTag('coretraffic', undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
|
|||||||
@@ -9,31 +9,26 @@ export interface ICoretrafficConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CoreTraffic {
|
export class CoreTraffic {
|
||||||
public projectinfo = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
|
public projectinfo!: plugins.projectinfo.ProjectinfoNpm;
|
||||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
public typedrouter: plugins.typedrequest.TypedRouter = new plugins.typedrequest.TypedRouter();
|
||||||
public coreflowConnector: CoreflowConnector;
|
public coreflowConnector: CoreflowConnector;
|
||||||
public taskmanager: CoretrafficTaskManager;
|
public taskmanager: CoretrafficTaskManager;
|
||||||
public networkProxy: plugins.smartproxy.NetworkProxy;
|
public smartProxy: plugins.smartproxy.SmartProxy;
|
||||||
public sslRedirect: plugins.smartproxy.SslRedirect;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.coreflowConnector = new CoreflowConnector(this);
|
this.coreflowConnector = new CoreflowConnector(this);
|
||||||
this.taskmanager = new CoretrafficTaskManager(this);
|
this.taskmanager = new CoretrafficTaskManager(this);
|
||||||
this.networkProxy = new plugins.smartproxy.NetworkProxy({
|
this.smartProxy = new plugins.smartproxy.SmartProxy({
|
||||||
port: 8000
|
routes: [],
|
||||||
});
|
});
|
||||||
this.sslRedirect = new plugins.smartproxy.SslRedirect(7999);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts coretraffic
|
* starts coretraffic
|
||||||
*/
|
*/
|
||||||
public async start() {
|
public async start() {
|
||||||
await this.networkProxy.start();
|
this.projectinfo = await plugins.projectinfo.ProjectinfoNpm.create(paths.packageDir);
|
||||||
await this.sslRedirect.start();
|
await this.smartProxy.start();
|
||||||
this.networkProxy.addDefaultHeaders({
|
|
||||||
servezone_coretraffic_version: this.projectinfo.version
|
|
||||||
})
|
|
||||||
|
|
||||||
await this.taskmanager.start();
|
await this.taskmanager.start();
|
||||||
await this.coreflowConnector.start();
|
await this.coreflowConnector.start();
|
||||||
@@ -47,9 +42,13 @@ export class CoreTraffic {
|
|||||||
console.log('stopped taskmanager');
|
console.log('stopped taskmanager');
|
||||||
await this.coreflowConnector.stop();
|
await this.coreflowConnector.stop();
|
||||||
console.log('stopped coreflowConnector');
|
console.log('stopped coreflowConnector');
|
||||||
await this.networkProxy.stop();
|
await this.smartProxy.stop();
|
||||||
console.log('stopped smartproxy!');
|
console.log('stopped smartproxy!');
|
||||||
await this.sslRedirect.stop();
|
}
|
||||||
|
|
||||||
|
public getDefaultResponseHeaders() {
|
||||||
|
return {
|
||||||
|
servezone_coretraffic_version: this.projectinfo?.version || 'unknown',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ export class CoretrafficTaskManager {
|
|||||||
/**
|
/**
|
||||||
* a task to run setup routing, runs buffered
|
* a task to run setup routing, runs buffered
|
||||||
*/
|
*/
|
||||||
public setupRoutingTask: plugins.taskbuffer.Task<plugins.tsclass.network.IReverseProxyConfig[]>;
|
public setupRoutingTask: plugins.taskbuffer.Task;
|
||||||
|
|
||||||
constructor(coretrafficRefArg: CoreTraffic) {
|
constructor(coretrafficRefArg: CoreTraffic) {
|
||||||
this.coretrafficRef = coretrafficRefArg;
|
this.coretrafficRef = coretrafficRefArg;
|
||||||
this.taskmanager = new plugins.taskbuffer.TaskManager();
|
this.taskmanager = new plugins.taskbuffer.TaskManager();
|
||||||
|
|
||||||
this.setupRoutingTask = new plugins.taskbuffer.Task({
|
this.setupRoutingTask = new plugins.taskbuffer.Task({
|
||||||
|
name: 'setupRouting',
|
||||||
buffered: true,
|
buffered: true,
|
||||||
bufferMax: 2,
|
bufferMax: 2,
|
||||||
taskFunction: async (reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
taskFunction: async (reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[]) => {
|
||||||
@@ -24,11 +25,78 @@ export class CoretrafficTaskManager {
|
|||||||
logger.log('info', `routing setup task triggered`);
|
logger.log('info', `routing setup task triggered`);
|
||||||
logger.log('info', `Found ${reverseConfigs.length} host reverse configs!`);
|
logger.log('info', `Found ${reverseConfigs.length} host reverse configs!`);
|
||||||
logger.log('info', `trying to deploy host candidates now`);
|
logger.log('info', `trying to deploy host candidates now`);
|
||||||
await this.coretrafficRef.networkProxy.updateProxyConfigs(reverseConfigs);
|
await this.coretrafficRef.smartProxy.updateRoutes(this.createRoutesFromReverseConfigs(reverseConfigs));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private createRoutesFromReverseConfigs(
|
||||||
|
reverseConfigs: plugins.tsclass.network.IReverseProxyConfig[]
|
||||||
|
): plugins.smartproxy.IRouteConfig[] {
|
||||||
|
const responseHeaders = this.coretrafficRef.getDefaultResponseHeaders();
|
||||||
|
const routes: plugins.smartproxy.IRouteConfig[] = [
|
||||||
|
{
|
||||||
|
name: 'http-to-https-redirect',
|
||||||
|
match: {
|
||||||
|
ports: 7999,
|
||||||
|
protocol: 'http',
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
type: 'socket-handler',
|
||||||
|
socketHandler: plugins.smartproxy.SocketHandlers.httpRedirect('https://{domain}{path}', 301),
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
response: responseHeaders,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const reverseConfig of reverseConfigs) {
|
||||||
|
routes.push({
|
||||||
|
name: `https-${reverseConfig.hostName}`,
|
||||||
|
match: {
|
||||||
|
ports: 8000,
|
||||||
|
domains: reverseConfig.hostName,
|
||||||
|
protocol: 'http',
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
type: 'forward',
|
||||||
|
targets: reverseConfig.destinationIps.flatMap((destinationIp) =>
|
||||||
|
reverseConfig.destinationPorts.map((destinationPort) => ({
|
||||||
|
host: destinationIp,
|
||||||
|
port: destinationPort,
|
||||||
|
}))
|
||||||
|
),
|
||||||
|
tls: {
|
||||||
|
mode: 'terminate',
|
||||||
|
certificate: {
|
||||||
|
key: reverseConfig.privateKey,
|
||||||
|
cert: reverseConfig.publicKey,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
response: responseHeaders,
|
||||||
|
},
|
||||||
|
security: reverseConfig.authentication
|
||||||
|
? {
|
||||||
|
basicAuth: {
|
||||||
|
enabled: true,
|
||||||
|
users: [
|
||||||
|
{
|
||||||
|
username: reverseConfig.authentication.user,
|
||||||
|
password: reverseConfig.authentication.pass,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
|
||||||
public async start() {}
|
public async start() {}
|
||||||
|
|
||||||
public async stop() {}
|
public async stop() {}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import * as plugins from './coretraffic.plugins.js';
|
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({
|
export const logger = new plugins.smartlog.Smartlog({
|
||||||
logContext: {
|
logContext: {
|
||||||
|
|||||||
+1
-2
@@ -6,11 +6,10 @@ import { logger } from './coretraffic.logging.js';
|
|||||||
import { CoreTraffic } from './coretraffic.classes.coretraffic.js';
|
import { CoreTraffic } from './coretraffic.classes.coretraffic.js';
|
||||||
export { CoreTraffic };
|
export { CoreTraffic };
|
||||||
|
|
||||||
const projectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
|
|
||||||
|
|
||||||
let coretrafficInstance: CoreTraffic;
|
let coretrafficInstance: CoreTraffic;
|
||||||
|
|
||||||
export const runCli = async () => {
|
export const runCli = async () => {
|
||||||
|
const projectinfo = await plugins.projectinfo.ProjectInfo.create(paths.packageDir);
|
||||||
logger.log('info', `coretraffic@v${projectinfo.npm.version}`);
|
logger.log('info', `coretraffic@v${projectinfo.npm.version}`);
|
||||||
coretrafficInstance = new CoreTraffic();
|
coretrafficInstance = new CoreTraffic();
|
||||||
await coretrafficInstance.start();
|
await coretrafficInstance.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user