Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
29549b126e | |||
736113eb4e | |||
3b2d140836 | |||
70690f6400 | |||
ae561e3e88 | |||
8a02a0c506 |
930
package-lock.json
generated
930
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": "1.0.37",
|
"version": "2.0.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a proxy for handling high workloads of proxying",
|
"description": "a proxy for handling high workloads of proxying",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -12,7 +12,7 @@ tap.test('should start the testproxy', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should supply reverse proxy config', async () => {
|
tap.test('should supply reverse proxy config', async () => {
|
||||||
testProxy.updateReversConfigs([
|
testProxy.updateReverseConfigs([
|
||||||
{
|
{
|
||||||
destinationIp: 'localhost',
|
destinationIp: 'localhost',
|
||||||
destinationPort: '3000',
|
destinationPort: '3000',
|
||||||
|
@ -231,7 +231,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.port}`);
|
console.log(`ProxyWorker -> OK: now listening for new connections on port ${this.port}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.IReverseProxyConfig[]) {
|
public async updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]) {
|
||||||
this.proxyConfigs = proxyConfigsArg;
|
this.proxyConfigs = proxyConfigsArg;
|
||||||
this.router.setNewProxyConfigs(proxyConfigsArg);
|
this.router.setNewProxyConfigs(proxyConfigsArg);
|
||||||
for (const hostCandidate of this.proxyConfigs) {
|
for (const hostCandidate of this.proxyConfigs) {
|
||||||
|
@ -19,7 +19,7 @@ export class SmartProxy {
|
|||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateReversConfigs(
|
public async updateReverseConfigs(
|
||||||
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
|
reverseConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]
|
||||||
) {
|
) {
|
||||||
// TODO search for old hostCandidates with that target
|
// TODO search for old hostCandidates with that target
|
||||||
|
@ -2,9 +2,23 @@ import * as plugins from './smartproxy.plugins';
|
|||||||
import { expose } from '@pushrocks/smartspawn';
|
import { expose } from '@pushrocks/smartspawn';
|
||||||
import * as net from 'net';
|
import * as net from 'net';
|
||||||
let netServer: plugins.net.Server;
|
let netServer: plugins.net.Server;
|
||||||
|
let httpServer: plugins.http.Server;
|
||||||
|
|
||||||
const portProxyCalls = {
|
const portProxyCalls = {
|
||||||
start: async (portArg = 8000) => {
|
start: async (portArg = 8000) => {
|
||||||
|
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(7999);
|
||||||
netServer = net
|
netServer = net
|
||||||
.createServer(from => {
|
.createServer(from => {
|
||||||
const to = net.createConnection({
|
const to = net.createConnection({
|
||||||
@ -19,9 +33,11 @@ const portProxyCalls = {
|
|||||||
},
|
},
|
||||||
stop: async () => {
|
stop: async () => {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
|
httpServer.close(() => {
|
||||||
netServer.close(() => {
|
netServer.close(() => {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user