]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/mock-servers/mock-instances-index.ts
Add new plugin/peertube version notifs
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / mock-servers / mock-instances-index.ts
CommitLineData
6f1b4fa4
C
1import * as express from 'express'
2
3export class MockInstancesIndex {
a1587156 4 private readonly indexInstances: { host: string, createdAt: string }[] = []
6f1b4fa4
C
5
6 initialize () {
ba5a8d89 7 return new Promise<void>(res => {
6f1b4fa4
C
8 const app = express()
9
10 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
11 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
12
13 return next()
14 })
15
16 app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => {
17 const since = req.query.since
18
19 const filtered = this.indexInstances.filter(i => {
20 if (!since) return true
21
22 return i.createdAt > since
23 })
24
25 return res.json({
26 total: filtered.length,
27 data: filtered
28 })
29 })
30
2ca154da 31 app.listen(42101, () => res())
6f1b4fa4
C
32 })
33 }
34
35 addInstance (host: string) {
36 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
37 }
38}