2021-08-25 08:08:37 -05:00
|
|
|
|
|
|
|
import { createServer, Server } from 'http'
|
2021-08-27 07:32:44 -05:00
|
|
|
import proxy from 'proxy'
|
2021-08-25 08:08:37 -05:00
|
|
|
import { randomInt } from '@shared/core-utils'
|
2021-09-06 01:13:11 -05:00
|
|
|
import { terminateServer } from './utils'
|
2021-08-25 08:08:37 -05:00
|
|
|
|
|
|
|
class MockProxy {
|
|
|
|
private server: Server
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
return new Promise<number>(res => {
|
2021-10-12 06:30:41 -05:00
|
|
|
const port = 46000 + randomInt(1, 1000)
|
2021-08-25 08:08:37 -05:00
|
|
|
|
|
|
|
this.server = proxy(createServer())
|
|
|
|
this.server.listen(port, () => res(port))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
terminate () {
|
2021-09-06 01:13:11 -05:00
|
|
|
return terminateServer(this.server)
|
2021-08-25 08:08:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
MockProxy
|
|
|
|
}
|