diff options
author | smilekison <24309222+smilekison@users.noreply.github.com> | 2021-08-25 06:08:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 15:08:37 +0200 |
commit | 8729a87024fc837f7dd6f13afeec90cf6dda1c06 (patch) | |
tree | 0f6f34966cf7b08d3024a08def4aa547d3aec459 /shared/extra-utils/mock-servers/mock-proxy.ts | |
parent | fdec51e3846d50e3375612a6820ed3ab0b5fcd25 (diff) | |
download | PeerTube-8729a87024fc837f7dd6f13afeec90cf6dda1c06.tar.gz PeerTube-8729a87024fc837f7dd6f13afeec90cf6dda1c06.tar.zst PeerTube-8729a87024fc837f7dd6f13afeec90cf6dda1c06.zip |
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 <me@florianbigard.com>
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-proxy.ts')
-rw-r--r-- | shared/extra-utils/mock-servers/mock-proxy.ts | 27 |
1 files changed, 27 insertions, 0 deletions
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 @@ | |||
1 | |||
2 | import { createServer, Server } from 'http' | ||
3 | import * as proxy from 'proxy' | ||
4 | import { randomInt } from '@shared/core-utils' | ||
5 | |||
6 | class MockProxy { | ||
7 | private server: Server | ||
8 | |||
9 | initialize () { | ||
10 | return new Promise<number>(res => { | ||
11 | const port = 42501 + randomInt(1, 100) | ||
12 | |||
13 | this.server = proxy(createServer()) | ||
14 | this.server.listen(port, () => res(port)) | ||
15 | }) | ||
16 | } | ||
17 | |||
18 | terminate () { | ||
19 | if (this.server) this.server.close() | ||
20 | } | ||
21 | } | ||
22 | |||
23 | // --------------------------------------------------------------------------- | ||
24 | |||
25 | export { | ||
26 | MockProxy | ||
27 | } | ||