1
0
Fork 0
peertube/shared/extra-utils/mock-servers/mock-proxy.ts

29 lines
578 B
TypeScript
Raw Normal View History

import { createServer, Server } from 'http'
2021-08-27 08:32:44 -04:00
import proxy from 'proxy'
import { randomInt } from '@shared/core-utils'
2021-09-06 02:13:11 -04:00
import { terminateServer } from './utils'
class MockProxy {
private server: Server
initialize () {
return new Promise<number>(res => {
const port = 42501 + randomInt(1, 100)
this.server = proxy(createServer())
this.server.listen(port, () => res(port))
})
}
terminate () {
2021-09-06 02:13:11 -04:00
return terminateServer(this.server)
}
}
// ---------------------------------------------------------------------------
export {
MockProxy
}