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

34 lines
865 B
TypeScript
Raw Normal View History

2021-03-11 16:54:52 +01:00
import * as express from 'express'
2021-04-15 13:52:27 +02:00
import { randomInt } from '@shared/core-utils'
2021-03-11 16:54:52 +01:00
export class MockJoinPeerTubeVersions {
private latestVersion: string
initialize () {
2021-04-15 13:52:27 +02:00
return new Promise<number>(res => {
2021-03-11 16:54:52 +01: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-04-15 13:52:27 +02:00
const port = 42201 + randomInt(1, 100)
app.listen(port, () => res(port))
2021-03-11 16:54:52 +01:00
})
}
setLatestVersion (latestVersion: string) {
this.latestVersion = latestVersion
}
}