]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/mock-servers/mock-proxy.ts
Add channel filters for my videos/followers
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / mock-servers / mock-proxy.ts
CommitLineData
8729a870 1
2import { createServer, Server } from 'http'
41fb13c3 3import proxy from 'proxy'
8729a870 4import { randomInt } from '@shared/core-utils'
70430c27 5import { terminateServer } from './utils'
8729a870 6
7class MockProxy {
8 private server: Server
9
10 initialize () {
11 return new Promise<number>(res => {
3c25d37a 12 const port = 46000 + randomInt(1, 1000)
8729a870 13
14 this.server = proxy(createServer())
15 this.server.listen(port, () => res(port))
16 })
17 }
18
19 terminate () {
70430c27 20 return terminateServer(this.server)
8729a870 21 }
22}
23
24// ---------------------------------------------------------------------------
25
26export {
27 MockProxy
28}