2019-05-08 16:12:02 +03:00
|
|
|
require('dotenv').config()
|
|
|
|
const express = require('express')
|
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-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
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
bridgeRouter.get('/', async (req, res, next) => {
|
2019-05-08 16:12:02 +03:00
|
|
|
try {
|
2020-01-10 15:55:35 +03:00
|
|
|
const results = await readFile(`./responses/${req.params.bridgeName}/getBalances.json`)
|
|
|
|
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
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
bridgeRouter.get('/validators', async (req, res, next) => {
|
2019-05-08 16:12:02 +03:00
|
|
|
try {
|
2020-01-10 15:55:35 +03:00
|
|
|
const results = await readFile(`./responses/${req.params.bridgeName}/validators.json`)
|
2019-05-08 16:12:02 +03:00
|
|
|
res.json(results)
|
|
|
|
} catch (e) {
|
|
|
|
// this will eventually be handled by your error handling middleware
|
|
|
|
next(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
bridgeRouter.get('/eventsStats', async (req, res, next) => {
|
2019-05-08 16:12:02 +03:00
|
|
|
try {
|
2020-01-10 15:55:35 +03:00
|
|
|
const results = await readFile(`./responses/${req.params.bridgeName}/eventsStats.json`)
|
2019-05-08 16:12:02 +03:00
|
|
|
res.json(results)
|
|
|
|
} catch (e) {
|
|
|
|
// this will eventually be handled by your error handling middleware
|
|
|
|
next(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
bridgeRouter.get('/alerts', async (req, res, next) => {
|
2019-05-08 16:12:02 +03:00
|
|
|
try {
|
2020-01-10 15:55:35 +03:00
|
|
|
const results = await readFile(`./responses/${req.params.bridgeName}/alerts.json`)
|
2019-05-08 16:12:02 +03:00
|
|
|
res.json(results)
|
|
|
|
} catch (e) {
|
|
|
|
next(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-10 15:55:35 +03:00
|
|
|
bridgeRouter.get('/stuckTransfers', async (req, res, next) => {
|
2019-05-08 16:12:02 +03:00
|
|
|
try {
|
2020-01-10 15:55:35 +03:00
|
|
|
const results = await readFile(`./responses/${req.params.bridgeName}/stuckTransfers.json`)
|
2019-05-08 16:12:02 +03:00
|
|
|
res.json(results)
|
|
|
|
} 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}!`))
|