WIPP
This commit is contained in:
parent
c3261bc61a
commit
e24da06a1b
3 changed files with 64 additions and 38 deletions
|
|
@ -14,10 +14,9 @@ const dbm = require('./postgresql_interface')
|
|||
const pairing = require('./pairing')
|
||||
const settingsLoader = require('./settings-loader')
|
||||
const plugins = require('./plugins')
|
||||
const helpers = require('./route-helpers')
|
||||
|
||||
module.exports = {
|
||||
init
|
||||
}
|
||||
module.exports = {init}
|
||||
|
||||
const CLOCK_SKEW = 60 * 1000
|
||||
const REQUEST_TTL = 3 * 60 * 1000
|
||||
|
|
@ -87,8 +86,7 @@ function trade (req, res, next) {
|
|||
}
|
||||
|
||||
function stateChange (req, res, next) {
|
||||
const pi = plugins(req.settings)
|
||||
pi.stateChange(req.deviceId, req.deviceTime, req.body)
|
||||
helpers.stateChange(req.deviceId, req.deviceTime, req.body)
|
||||
.then(() => cacheAndRespond(req, res))
|
||||
.catch(next)
|
||||
}
|
||||
|
|
@ -190,8 +188,7 @@ function updatePhone (req, res, next) {
|
|||
}
|
||||
|
||||
function fetchPhoneTx (req, res, next) {
|
||||
const pi = plugins(req.settings)
|
||||
return pi.fetchPhoneTx(req.query.phone)
|
||||
return helpers.fetchPhoneTx(req.query.phone)
|
||||
.then(r => res.json(r))
|
||||
.catch(next)
|
||||
}
|
||||
|
|
@ -337,9 +334,22 @@ function init (opts) {
|
|||
? (req, res, next) => next()
|
||||
: authorize
|
||||
|
||||
const configRequiredRoutes = [
|
||||
'/poll',
|
||||
'/trade',
|
||||
'/send',
|
||||
'/cash_out',
|
||||
'/dispense_ack',
|
||||
'/event',
|
||||
'/verify_user',
|
||||
'/verify_transaction',
|
||||
'/phone_code'
|
||||
]
|
||||
|
||||
app.use(morgan('dev', {skip}))
|
||||
app.use(helmet())
|
||||
app.use(populateDeviceId)
|
||||
app.use(configRequiredRoutes, populateSettings)
|
||||
app.use(bodyParser.json())
|
||||
app.use(filterOldRequests)
|
||||
app.post('*', cacheAction)
|
||||
|
|
@ -409,3 +419,15 @@ function populateDeviceId (req, res, next) {
|
|||
|
||||
next()
|
||||
}
|
||||
|
||||
function populateSettings (req, res, next) {
|
||||
const versionId = req.headers['config-version-id']
|
||||
if (!versionId) {
|
||||
logger.debug('No config-version-id header')
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
settingsLoader.log(versionId)
|
||||
.then(settings => { req.settings = settings })
|
||||
.catch(next)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue