2021-08-25 09:08:37 -04:00
|
|
|
|
|
|
|
import { createServer, Server } from 'http'
|
2021-08-27 08:32:44 -04:00
|
|
|
import proxy from 'proxy'
|
2021-08-25 09:08:37 -04:00
|
|
|
import { randomInt } from '@shared/core-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 () {
|
|
|
|
if (this.server) this.server.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
MockProxy
|
|
|
|
}
|