From 8729a87024fc837f7dd6f13afeec90cf6dda1c06 Mon Sep 17 00:00:00 2001 From: smilekison <24309222+smilekison@users.noreply.github.com> Date: Wed, 25 Aug 2021 06:08:37 -0700 Subject: Support proxies for PeerTube (#4346) * Updated with latest code * Updated Support proxies for PeerTube * Support Proxies for PeerTube (Updated with change request) * Cleanup proxy PR Co-authored-by: Chocobozzz --- shared/extra-utils/mock-servers/mock-proxy.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 shared/extra-utils/mock-servers/mock-proxy.ts (limited to 'shared/extra-utils') diff --git a/shared/extra-utils/mock-servers/mock-proxy.ts b/shared/extra-utils/mock-servers/mock-proxy.ts new file mode 100644 index 000000000..5365f87d1 --- /dev/null +++ b/shared/extra-utils/mock-servers/mock-proxy.ts @@ -0,0 +1,27 @@ + +import { createServer, Server } from 'http' +import * as proxy from 'proxy' +import { randomInt } from '@shared/core-utils' + +class MockProxy { + private server: Server + + initialize () { + return new Promise(res => { + const port = 42501 + randomInt(1, 100) + + this.server = proxy(createServer()) + this.server.listen(port, () => res(port)) + }) + } + + terminate () { + if (this.server) this.server.close() + } +} + +// --------------------------------------------------------------------------- + +export { + MockProxy +} -- cgit v1.2.3