diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts')
-rw-r--r-- | shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts b/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts new file mode 100644 index 000000000..5ea432ecf --- /dev/null +++ b/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | import * as express from 'express' | ||
2 | import { randomInt } from '@shared/core-utils' | ||
3 | |||
4 | export class MockJoinPeerTubeVersions { | ||
5 | private latestVersion: string | ||
6 | |||
7 | initialize () { | ||
8 | return new Promise<number>(res => { | ||
9 | const app = express() | ||
10 | |||
11 | app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
12 | if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) | ||
13 | |||
14 | return next() | ||
15 | }) | ||
16 | |||
17 | app.get('/versions.json', (req: express.Request, res: express.Response) => { | ||
18 | return res.json({ | ||
19 | peertube: { | ||
20 | latestVersion: this.latestVersion | ||
21 | } | ||
22 | }) | ||
23 | }) | ||
24 | |||
25 | const port = 42201 + randomInt(1, 100) | ||
26 | app.listen(port, () => res(port)) | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | setLatestVersion (latestVersion: string) { | ||
31 | this.latestVersion = latestVersion | ||
32 | } | ||
33 | } | ||