Add Lamassu support microsite
This commit is contained in:
parent
4f9cc88a5e
commit
d901a36f29
5 changed files with 13347 additions and 12 deletions
|
|
@ -15,6 +15,7 @@ const helmet = require('helmet')
|
|||
const WebSocket = require('ws')
|
||||
const http = require('http')
|
||||
const SocketIo = require('socket.io')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const machineLoader = require('../machine-loader')
|
||||
const T = require('../time')
|
||||
|
|
@ -31,7 +32,7 @@ const customers = require('../customers')
|
|||
const logs = require('../logs')
|
||||
const supportLogs = require('../support_logs')
|
||||
const funding = require('./funding')
|
||||
const _ = require('lodash/fp')
|
||||
const supportServer = require('./admin-support')
|
||||
|
||||
const NEVER = new Date(Date.now() + 100 * T.years)
|
||||
const REAUTHENTICATE_INTERVAL = T.minute
|
||||
|
|
@ -72,7 +73,6 @@ app.use(helmet({noCache: true}))
|
|||
app.use(cookieParser())
|
||||
app.use(register)
|
||||
app.use(authenticate)
|
||||
|
||||
app.use(bodyParser.json())
|
||||
|
||||
app.get('/api/totem', (req, res) => {
|
||||
|
|
@ -212,7 +212,10 @@ app.get('/api/support_logs', (req, res, next) => {
|
|||
app.get('/api/support_logs/logs', (req, res, next) => {
|
||||
return supportLogs.get(req.query.supportLogId)
|
||||
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
||||
.then(log => logs.getMachineLogs(log.deviceId, log.timestamp))
|
||||
.then(result => {
|
||||
const log = result || {}
|
||||
return logs.getMachineLogs(log.deviceId, log.timestamp)
|
||||
})
|
||||
.then(r => res.send(r))
|
||||
.catch(next)
|
||||
})
|
||||
|
|
@ -330,13 +333,12 @@ wss.on('connection', ws => {
|
|||
})
|
||||
|
||||
function run () {
|
||||
if (devMode) {
|
||||
webServer.listen(8070, () => {
|
||||
console.log('lamassu-admin-server listening on port 8070')
|
||||
})
|
||||
} else {
|
||||
webServer.listen(443, () => {
|
||||
console.log('lamassu-admin-server listening on port 443')
|
||||
})
|
||||
}
|
||||
const serverPort = devMode ? 8070 : 443
|
||||
const supportPort = 8071
|
||||
|
||||
const serverLog = `lamassu-admin-server listening on port ${serverPort}`
|
||||
const supportLog = `lamassu-support-server listening on port ${supportPort}`
|
||||
|
||||
webServer.listen(serverPort, () => console.log(serverLog))
|
||||
supportServer.run(supportPort, () => console.log(supportLog))
|
||||
}
|
||||
|
|
|
|||
65
lib/admin/admin-support.js
Normal file
65
lib/admin/admin-support.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
const fs = require('fs')
|
||||
const bodyParser = require('body-parser')
|
||||
const cookieParser = require('cookie-parser')
|
||||
const helmet = require('helmet')
|
||||
const morgan = require('morgan')
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const https = require('https')
|
||||
const _ = require('lodash/fp')
|
||||
const serveStatic = require('serve-static')
|
||||
const path = require('path')
|
||||
|
||||
const logs = require('../logs')
|
||||
const supportLogs = require('../support_logs')
|
||||
const options = require('../options')
|
||||
|
||||
const caOptions = {
|
||||
ca: '/etc/ssl/certs/Lamassu_CA.pem'
|
||||
}
|
||||
|
||||
app.use(morgan('dev'))
|
||||
app.use(helmet({noCache: true}))
|
||||
app.use(cookieParser())
|
||||
app.use(bodyParser.json())
|
||||
app.use(serveStatic(path.resolve(__dirname, '..', '..', 'public'), {
|
||||
'index': ['support-index.html']
|
||||
}))
|
||||
|
||||
const certOptions = {
|
||||
key: fs.readFileSync(options.keyPath),
|
||||
cert: fs.readFileSync(options.certPath),
|
||||
ca: [fs.readFileSync(caOptions.ca)],
|
||||
requestCert: true,
|
||||
rejectUnauthorized: true
|
||||
}
|
||||
|
||||
app.get('/api/support_logs', (req, res, next) => {
|
||||
return supportLogs.batch()
|
||||
.then(supportLogs => res.send({ supportLogs }))
|
||||
.catch(next)
|
||||
})
|
||||
|
||||
app.get('/api/support_logs/logs', (req, res, next) => {
|
||||
return supportLogs.get(req.query.supportLogId)
|
||||
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
||||
.then(result => {
|
||||
const log = result || {}
|
||||
return logs.getMachineLogs(log.deviceId, log.timestamp)
|
||||
})
|
||||
.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)
|
||||
})
|
||||
|
||||
function run (port, cb) {
|
||||
const webServer = https.createServer(certOptions, app)
|
||||
webServer.listen(port || 443, cb)
|
||||
}
|
||||
|
||||
module.exports = { run }
|
||||
Loading…
Add table
Add a link
Reference in a new issue