PeerTube/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts

34 lines
861 B
TypeScript
Raw Normal View History

2021-08-27 07:32:44 -05:00
import express from 'express'
2021-04-15 06:52:27 -05:00
import { randomInt } from '@shared/core-utils'
2021-03-11 09:54:52 -06:00
export class MockJoinPeerTubeVersions {
private latestVersion: string
initialize () {
2021-04-15 06:52:27 -05:00
return new Promise<number>(res => {
2021-03-11 09:54:52 -06:00
const app = express()
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
return next()
})
app.get('/versions.json', (req: express.Request, res: express.Response) => {
return res.json({
peertube: {
latestVersion: this.latestVersion
}
})
})
2021-10-12 06:30:41 -05:00
const port = 43000 + randomInt(1, 1000)
2021-04-15 06:52:27 -05:00
app.listen(port, () => res(port))
2021-03-11 09:54:52 -06:00
})
}
setLatestVersion (latestVersion: string) {
this.latestVersion = latestVersion
}
}