Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
4f1db106fb | |||
d47829a8b2 | |||
ca55d06244 | |||
7284924b26 | |||
10857aa12b | |||
c968c7f844 | |||
b07015f6c4 | |||
ca4ddade17 | |||
17eaea4124 | |||
d3d8f6ff57 | |||
906661c7f4 | |||
ea46caebb7 | |||
973e896fbf | |||
4605035b01 |
@ -12,20 +12,12 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
@ -36,6 +28,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
@ -96,10 +89,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -119,11 +111,10 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartproxy",
|
"gitrepo": "smartproxy",
|
||||||
"shortDescription": "a proxy for handling high workloads of proxying",
|
"description": "a proxy for handling high workloads of proxying",
|
||||||
"npmPackagename": "@pushrocks/smartproxy",
|
"npmPackagename": "@pushrocks/smartproxy",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
|
596
package-lock.json
generated
596
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.1",
|
"version": "3.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a proxy for handling high workloads of proxying",
|
"description": "a proxy for handling high workloads of proxying",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -11,7 +11,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web --allowimplicitany)",
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.63",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
@ -21,9 +22,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^6.0.0",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartnetwork": "^3.0.0",
|
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrequest": "^1.1.56",
|
"@pushrocks/smartrequest": "^2.0.0",
|
||||||
"@pushrocks/smartstring": "^4.0.2",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@tsclass/tsclass": "^4.0.17",
|
"@tsclass/tsclass": "^4.0.17",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
|
@ -5,7 +5,7 @@ let testProxy: smartproxy.NetworkProxy;
|
|||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testProxy = new smartproxy.NetworkProxy({
|
testProxy = new smartproxy.NetworkProxy({
|
||||||
port: 3001
|
port: 3001,
|
||||||
});
|
});
|
||||||
expect(testProxy).toBeInstanceOf(smartproxy.NetworkProxy);
|
expect(testProxy).toBeInstanceOf(smartproxy.NetworkProxy);
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartproxy',
|
name: '@pushrocks/smartproxy',
|
||||||
version: '3.0.1',
|
version: '3.0.8',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './smartproxy.classes.networkproxy.js'
|
export * from './smartproxy.classes.networkproxy.js';
|
||||||
export * from './smartproxy.portproxy.js';
|
export * from './smartproxy.portproxy.js';
|
||||||
|
export * from './smartproxy.classes.sslredirect.js'
|
@ -6,7 +6,6 @@ export interface INetworkProxyOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class NetworkProxy {
|
export class NetworkProxy {
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public options: INetworkProxyOptions;
|
public options: INetworkProxyOptions;
|
||||||
public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
public proxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];
|
||||||
@ -118,9 +117,6 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
console.log('got request');
|
|
||||||
const destinationConfig = this.router.routeReq(req);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* endRequest function
|
* endRequest function
|
||||||
* can be used to prematurely end a request
|
* can be used to prematurely end a request
|
||||||
@ -134,6 +130,15 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
res.end(messageArg);
|
res.end(messageArg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('got request');
|
||||||
|
const destinationConfig = this.router.routeReq(req);
|
||||||
|
|
||||||
|
if (!destinationConfig) {
|
||||||
|
console.log(`${req.headers.host} can't be routed properly. Terminating request.`);
|
||||||
|
endRequest();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// authentication
|
// authentication
|
||||||
if (destinationConfig.authentication) {
|
if (destinationConfig.authentication) {
|
||||||
const authInfo = destinationConfig.authentication;
|
const authInfo = destinationConfig.authentication;
|
||||||
@ -276,7 +281,9 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.httpsServer.listen(this.options.port);
|
this.httpsServer.listen(this.options.port);
|
||||||
console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.options.port}`);
|
console.log(
|
||||||
|
`ProxyWorker -> OK: now listening for new connections on port ${this.options.port}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
||||||
@ -306,8 +313,12 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
});
|
});
|
||||||
this.httpsServer;
|
this.httpsServer;
|
||||||
}
|
}
|
||||||
/* this.httpsServer.close();
|
}
|
||||||
this.httpsServer.listen(this.port); */
|
|
||||||
|
public async addDefaultHeaders(headersArg: { [key: string]: string }) {
|
||||||
|
for (const headerKey of Object.keys(headersArg)) {
|
||||||
|
this.defaultHeaders[headerKey] = headersArg[headerKey];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
|
32
ts/smartproxy.classes.sslredirect.ts
Normal file
32
ts/smartproxy.classes.sslredirect.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import * as plugins from './smartproxy.plugins.js';
|
||||||
|
|
||||||
|
export class SslRedirect {
|
||||||
|
httpServer: plugins.http.Server;
|
||||||
|
port: number;
|
||||||
|
constructor(portArg: number) {
|
||||||
|
this.port = portArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start() {
|
||||||
|
this.httpServer = plugins.http.createServer((request, response) => {
|
||||||
|
const requestUrl = new URL(request.url, `http://${request.headers.host}`);
|
||||||
|
const completeUrlWithoutProtocol = `${requestUrl.host}${requestUrl.pathname}${requestUrl.search}`;
|
||||||
|
const redirectUrl = `https://${completeUrlWithoutProtocol}`;
|
||||||
|
console.log(`Got http request for http://${completeUrlWithoutProtocol}`);
|
||||||
|
console.log(`Redirecting to ${redirectUrl}`);
|
||||||
|
response.writeHead(302, {
|
||||||
|
Location: redirectUrl,
|
||||||
|
});
|
||||||
|
response.end();
|
||||||
|
});
|
||||||
|
this.httpServer.listen(this.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
|
this.httpServer.close(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
await done.promise;
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +1,17 @@
|
|||||||
import * as plugins from './smartproxy.plugins.js';
|
import * as plugins from './smartproxy.plugins.js';
|
||||||
import * as net from 'net';
|
import * as net from 'net';
|
||||||
let netServer: plugins.net.Server;
|
|
||||||
let httpServer: plugins.http.Server;
|
|
||||||
|
|
||||||
export class PortProxy {
|
export class PortProxy {
|
||||||
|
netServer: plugins.net.Server;
|
||||||
fromPort: number;
|
fromPort: number;
|
||||||
toPort: number;
|
toPort: number;
|
||||||
|
|
||||||
constructor(fromPortArg: number, toPortArg: number) {
|
constructor(fromPortArg: number, toPortArg: number) {
|
||||||
this.fromPort = fromPortArg;
|
this.fromPort = fromPortArg;
|
||||||
this.toPort = toPortArg
|
this.toPort = toPortArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start () {
|
public async start() {
|
||||||
httpServer = plugins.http.createServer((request, response) => {
|
|
||||||
const requestUrl = new URL(request.url, `http://${request.headers.host}`);
|
|
||||||
const completeUrlWithoutProtocol = `${requestUrl.host}${requestUrl.pathname}${requestUrl.search}`;
|
|
||||||
const redirectUrl = `https://${completeUrlWithoutProtocol}`;
|
|
||||||
console.log(`Got http request for http://${completeUrlWithoutProtocol}`);
|
|
||||||
console.log(`Redirecting to ${redirectUrl}`);
|
|
||||||
response.writeHead(302, {
|
|
||||||
Location: redirectUrl,
|
|
||||||
});
|
|
||||||
response.end();
|
|
||||||
});
|
|
||||||
httpServer.listen(this.fromPort);
|
|
||||||
const cleanUpSockets = (from: plugins.net.Socket, to: plugins.net.Socket) => {
|
const cleanUpSockets = (from: plugins.net.Socket, to: plugins.net.Socket) => {
|
||||||
from.end();
|
from.end();
|
||||||
to.end();
|
to.end();
|
||||||
@ -34,8 +21,8 @@ export class PortProxy {
|
|||||||
to.unpipe();
|
to.unpipe();
|
||||||
from.destroy();
|
from.destroy();
|
||||||
to.destroy();
|
to.destroy();
|
||||||
}
|
};
|
||||||
netServer = net
|
this.netServer = net
|
||||||
.createServer((from) => {
|
.createServer((from) => {
|
||||||
const to = net.createConnection({
|
const to = net.createConnection({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
@ -64,10 +51,10 @@ export class PortProxy {
|
|||||||
});
|
});
|
||||||
from.on('end', () => {
|
from.on('end', () => {
|
||||||
cleanUpSockets(from, to);
|
cleanUpSockets(from, to);
|
||||||
})
|
});
|
||||||
to.on('end', () => {
|
to.on('end', () => {
|
||||||
cleanUpSockets(from, to);
|
cleanUpSockets(from, to);
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.listen(this.fromPort);
|
.listen(this.fromPort);
|
||||||
console.log(`PortProxy -> OK: Now listening on port ${this.fromPort}`);
|
console.log(`PortProxy -> OK: Now listening on port ${this.fromPort}`);
|
||||||
@ -75,11 +62,9 @@ export class PortProxy {
|
|||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
httpServer.close(() => {
|
this.netServer.close(() => {
|
||||||
netServer.close(() => {
|
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
await done.promise;
|
await done.promise;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
Reference in New Issue
Block a user