2019-05-08 15:12:02 +02:00
|
|
|
require('dotenv').config()
|
|
|
|
const express = require('express')
|
2020-10-12 21:16:41 +03:00
|
|
|
const cors = require('cors')
|
2020-01-10 09:55:35 -03:00
|
|
|
const { readFile } = require('./utils/file')
|
2019-05-08 15:12:02 +02:00
|
|
|
|
|
|
|
const app = express()
|
2020-01-10 09:55:35 -03:00
|
|
|
const bridgeRouter = express.Router({ mergeParams: true })
|
2019-05-08 15:12:02 +02:00
|
|
|
|
2020-10-12 21:16:41 +03:00
|
|
|
app.use(cors())
|
|
|
|
|
2020-02-03 09:48:28 -03:00
|
|
|
app.get('/favicon.ico', (req, res) => res.sendStatus(204))
|
2020-01-10 09:55:35 -03:00
|
|
|
app.use('/:bridgeName', bridgeRouter)
|
2019-05-08 15:12:02 +02:00
|
|
|
|
2021-02-26 05:39:48 +03:00
|
|
|
bridgeRouter.get('/:file(validators|eventsStats|alerts|mediators|stuckTransfers|failures)?', (req, res, next) => {
|
2019-05-08 15:12:02 +02:00
|
|
|
try {
|
2021-02-19 04:26:07 +03:00
|
|
|
const { bridgeName, file } = req.params
|
2021-02-26 05:39:48 +03:00
|
|
|
const results = readFile(`./responses/${bridgeName}/${file || 'getBalances'}.json`)
|
2020-01-10 09:55:35 -03:00
|
|
|
res.json(results)
|
2019-05-08 15:12:02 +02:00
|
|
|
} catch (e) {
|
2020-01-10 09:55:35 -03:00
|
|
|
// this will eventually be handled by your error handling middleware
|
|
|
|
next(e)
|
2019-06-03 09:47:12 -03:00
|
|
|
}
|
2020-01-10 09:55:35 -03:00
|
|
|
})
|
2019-06-03 09:47:12 -03:00
|
|
|
|
2021-02-26 05:39:48 +03:00
|
|
|
bridgeRouter.get('/metrics', (req, res, next) => {
|
|
|
|
try {
|
2021-04-02 12:59:49 +03:00
|
|
|
const { bridgeName } = req.params
|
|
|
|
const metrics = readFile(`./responses/${bridgeName}/metrics.txt`, false)
|
2021-02-26 05:39:48 +03:00
|
|
|
res.type('text').send(metrics)
|
|
|
|
} catch (e) {
|
|
|
|
next(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-09-13 09:11:38 +02:00
|
|
|
const port = process.env.MONITOR_PORT || 3003
|
2019-05-08 15:12:02 +02:00
|
|
|
app.set('port', port)
|
2019-05-30 13:18:48 +02:00
|
|
|
app.listen(port, () => console.log(`Monitoring app listening on port ${port}!`))
|