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