aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/server-commands/mock-servers/mock-joinpeertube-versions.ts')
-rw-r--r--shared/server-commands/mock-servers/mock-joinpeertube-versions.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts b/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts
new file mode 100644
index 000000000..e7906ea56
--- /dev/null
+++ b/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts
@@ -0,0 +1,34 @@
1import express from 'express'
2import { Server } from 'http'
3import { getPort, randomListen } from './utils'
4
5export class MockJoinPeerTubeVersions {
6 private server: Server
7 private latestVersion: string
8
9 async initialize () {
10 const app = express()
11
12 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
14
15 return next()
16 })
17
18 app.get('/versions.json', (req: express.Request, res: express.Response) => {
19 return res.json({
20 peertube: {
21 latestVersion: this.latestVersion
22 }
23 })
24 })
25
26 this.server = await randomListen(app)
27
28 return getPort(this.server)
29 }
30
31 setLatestVersion (latestVersion: string) {
32 this.latestVersion = latestVersion
33 }
34}