* feat: transactions page * fix: remove unused txHash function * refactor: rewrite transactions sql queries * fix: use left instead of inner join on txs * fix: change expandable table logic * fix: add other coins * refactor: move log download function to component * refactor: use name values in RadioGroup * fix: assorted fixes * feat: virtualize expandable table * fix: clean up imports * fix: remove border radius * fix: move formatting out of CopyToClipboard And use CSS instead of JS to format. * fix: remove customer's last name formatting This was using lodash's string case functions, which produce unwanted results if, for instance, a user has a double-barrel last name.
104 lines
2.5 KiB
JavaScript
104 lines
2.5 KiB
JavaScript
const bodyParser = require('body-parser')
|
|
const cors = require('cors')
|
|
const express = require('express')
|
|
const http = require('http')
|
|
const got = require('got')
|
|
|
|
const supportLogs = require('../support_logs')
|
|
const machineLoader = require('../machine-loader')
|
|
const logs = require('../logs')
|
|
const transactions = require('./transactions')
|
|
|
|
const serverLogs = require('./server-logs')
|
|
const supervisor = require('./supervisor')
|
|
const funding = require('./funding')
|
|
const config = require('./config')
|
|
|
|
const devMode = require('minimist')(process.argv.slice(2)).dev
|
|
|
|
const app = express()
|
|
app.use(bodyParser.json())
|
|
|
|
if (devMode) {
|
|
app.use(cors())
|
|
}
|
|
|
|
app.get('/api/config', async (req, res, next) => {
|
|
const state = config.getConfig(req.params.config)
|
|
const data = await config.fetchData()
|
|
res.json({ state, data })
|
|
next()
|
|
})
|
|
|
|
app.post('/api/config', (req, res, next) => {
|
|
config.saveConfig(req.body)
|
|
.then(it => res.json(it))
|
|
.then(() => dbNotify())
|
|
.catch(next)
|
|
})
|
|
|
|
app.get('/api/funding', (req, res) => {
|
|
return funding.getFunding()
|
|
.then(r => res.json(r))
|
|
})
|
|
|
|
app.get('/api/machines', (req, res) => {
|
|
machineLoader.getMachineNames()
|
|
.then(r => res.send({ machines: r }))
|
|
})
|
|
|
|
app.get('/api/logs/:deviceId', (req, res, next) => {
|
|
return logs.getMachineLogs(req.params.deviceId)
|
|
.then(r => res.send(r))
|
|
.catch(next)
|
|
})
|
|
|
|
app.post('/api/support_logs', (req, res, next) => {
|
|
return supportLogs.insert(req.query.deviceId)
|
|
.then(r => res.send(r))
|
|
.catch(next)
|
|
})
|
|
|
|
app.get('/api/version', (req, res, next) => {
|
|
res.send(require('../../package.json').version)
|
|
})
|
|
|
|
app.get('/api/uptimes', (req, res, next) => {
|
|
return supervisor.getAllProcessInfo()
|
|
.then(r => res.send(r))
|
|
.catch(next)
|
|
})
|
|
|
|
app.post('/api/server_support_logs', (req, res, next) => {
|
|
return serverLogs.insert()
|
|
.then(r => res.send(r))
|
|
.catch(next)
|
|
})
|
|
|
|
app.get('/api/server_logs', (req, res, next) => {
|
|
return serverLogs.getServerLogs()
|
|
.then(r => res.send(r))
|
|
.catch(next)
|
|
})
|
|
|
|
app.get('/api/txs', (req, res, next) => {
|
|
return transactions.batch()
|
|
.then(r => res.send(r))
|
|
.catch(next)
|
|
})
|
|
|
|
function dbNotify () {
|
|
return got.post('http://localhost:3030/dbChange')
|
|
.catch(e => console.error('Error: lamassu-server not responding'))
|
|
}
|
|
|
|
function run () {
|
|
const serverPort = 8070
|
|
|
|
const serverLog = `lamassu-admin-server listening on port ${serverPort}`
|
|
|
|
const webServer = http.createServer(app)
|
|
webServer.listen(serverPort, () => console.log(serverLog))
|
|
}
|
|
|
|
module.exports = { run }
|