1 import * as express from 'express'
3 export class MockInstancesIndex {
4 private readonly indexInstances: { host: string, createdAt: string }[] = []
7 return new Promise(res => {
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)
16 app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => {
17 const since = req.query.since
19 const filtered = this.indexInstances.filter(i => {
20 if (!since) return true
22 return i.createdAt > since
26 total: filtered.length,
31 app.listen(42100, () => res())
35 addInstance (host: string) {
36 this.indexInstances.push({ host, createdAt: new Date().toISOString() })