2021-08-27 14:32:44 +02:00
|
|
|
import express from 'express'
|
2021-10-22 14:31:38 +02:00
|
|
|
import { Server } from 'http'
|
|
|
|
import { getPort, randomListen } from './utils'
|
2021-03-11 16:54:52 +01:00
|
|
|
|
|
|
|
export class MockJoinPeerTubeVersions {
|
2021-10-22 14:31:38 +02:00
|
|
|
private server: Server
|
2021-03-11 16:54:52 +01:00
|
|
|
private latestVersion: string
|
|
|
|
|
2021-10-22 14:31:38 +02:00
|
|
|
async initialize () {
|
|
|
|
const app = express()
|
2021-03-11 16:54:52 +01:00
|
|
|
|
2021-10-22 14:31:38 +02:00
|
|
|
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)
|
2021-03-11 16:54:52 +01:00
|
|
|
|
2021-10-22 14:31:38 +02:00
|
|
|
return next()
|
|
|
|
})
|
2021-03-11 16:54:52 +01:00
|
|
|
|
2021-10-22 14:31:38 +02:00
|
|
|
app.get('/versions.json', (req: express.Request, res: express.Response) => {
|
|
|
|
return res.json({
|
|
|
|
peertube: {
|
|
|
|
latestVersion: this.latestVersion
|
|
|
|
}
|
2021-03-11 16:54:52 +01:00
|
|
|
})
|
|
|
|
})
|
2021-10-22 14:31:38 +02:00
|
|
|
|
|
|
|
this.server = await randomListen(app)
|
|
|
|
|
|
|
|
return getPort(this.server)
|
2021-03-11 16:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setLatestVersion (latestVersion: string) {
|
|
|
|
this.latestVersion = latestVersion
|
|
|
|
}
|
|
|
|
}
|