feat: reject requests from incompatible machines
This commit is contained in:
parent
737672c07a
commit
1830f90c2c
5 changed files with 31 additions and 19 deletions
24
lib/middlewares/rejectIncompatbleMachines.js
Normal file
24
lib/middlewares/rejectIncompatbleMachines.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const semver = require('semver')
|
||||||
|
const version = require('../../package.json').version
|
||||||
|
const logger = require('../logger')
|
||||||
|
|
||||||
|
const rejectIncompatibleMachines = function (req, res, next) {
|
||||||
|
const machineVersion = req.query.version
|
||||||
|
const deviceId = req.deviceId
|
||||||
|
|
||||||
|
if (!machineVersion) return next()
|
||||||
|
|
||||||
|
const serverMajor = semver.major(version)
|
||||||
|
const machineMajor = semver.major(machineVersion)
|
||||||
|
|
||||||
|
if (serverMajor - machineMajor > 1) {
|
||||||
|
logger.error(`Machine version too old: ${machineVersion} deviceId: ${deviceId}`)
|
||||||
|
return res.status(400).json({
|
||||||
|
error: 'Machine version too old'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = rejectIncompatibleMachines
|
||||||
|
|
@ -22,7 +22,7 @@ const logsRoutes = require('./routes/logsRoutes')
|
||||||
const pairingRoutes = require('./routes/pairingRoutes')
|
const pairingRoutes = require('./routes/pairingRoutes')
|
||||||
const diagnosticsRoutes = require('./routes/diagnosticsRoutes')
|
const diagnosticsRoutes = require('./routes/diagnosticsRoutes')
|
||||||
const performanceRoutes = require('./routes/performanceRoutes')
|
const performanceRoutes = require('./routes/performanceRoutes')
|
||||||
const pollingRoutes = require('./routes/pollingRoutes')
|
const rejectIncompatibleMachines = require('./middlewares/rejectIncompatbleMachines')
|
||||||
const stateRoutes = require('./routes/stateRoutes')
|
const stateRoutes = require('./routes/stateRoutes')
|
||||||
const termsAndConditionsRoutes = require('./routes/termsAndConditionsRoutes')
|
const termsAndConditionsRoutes = require('./routes/termsAndConditionsRoutes')
|
||||||
const { router: txRoutes } = require('./routes/txRoutes')
|
const { router: txRoutes } = require('./routes/txRoutes')
|
||||||
|
|
@ -81,7 +81,6 @@ const loadRoutes = async () => {
|
||||||
|
|
||||||
// other app routes
|
// other app routes
|
||||||
app.use('/graphql', recordPing)
|
app.use('/graphql', recordPing)
|
||||||
app.use('/poll', pollingRoutes)
|
|
||||||
app.use('/terms_conditions', termsAndConditionsRoutes)
|
app.use('/terms_conditions', termsAndConditionsRoutes)
|
||||||
app.use('/state', stateRoutes)
|
app.use('/state', stateRoutes)
|
||||||
app.use('/cashbox', cashboxRoutes)
|
app.use('/cashbox', cashboxRoutes)
|
||||||
|
|
@ -103,6 +102,9 @@ const loadRoutes = async () => {
|
||||||
|
|
||||||
app.use('/probe', probeRoutes)
|
app.use('/probe', probeRoutes)
|
||||||
|
|
||||||
|
// Not all requests have the machine version on the url
|
||||||
|
// rejecting poll is enough to render the machine "stuck"
|
||||||
|
app.use(rejectIncompatibleMachines)
|
||||||
await graphQLServer.start()
|
await graphQLServer.start()
|
||||||
app.use('/graphql',
|
app.use('/graphql',
|
||||||
express.json(),
|
express.json(),
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
const express = require('express')
|
|
||||||
const nmd = require('nano-markdown')
|
|
||||||
const _ = require('lodash/fp')
|
|
||||||
|
|
||||||
const router = express.Router()
|
|
||||||
|
|
||||||
const version = require('../../package.json').version
|
|
||||||
|
|
||||||
function poll (req, res) {
|
|
||||||
return res.json({ version })
|
|
||||||
}
|
|
||||||
|
|
||||||
router.get('/', poll)
|
|
||||||
|
|
||||||
module.exports = router
|
|
||||||
3
package-lock.json
generated
3
package-lock.json
generated
|
|
@ -86,7 +86,7 @@
|
||||||
"promise-sequential": "^1.1.1",
|
"promise-sequential": "^1.1.1",
|
||||||
"queue-promise": "^2.2.1",
|
"queue-promise": "^2.2.1",
|
||||||
"request-promise": "^4.2.6",
|
"request-promise": "^4.2.6",
|
||||||
"semver": "^7.1.3",
|
"semver": "^7.7.1",
|
||||||
"serve-static": "^1.12.4",
|
"serve-static": "^1.12.4",
|
||||||
"talisman": "^0.20.0",
|
"talisman": "^0.20.0",
|
||||||
"telnyx": "^1.25.5",
|
"telnyx": "^1.25.5",
|
||||||
|
|
@ -18226,6 +18226,7 @@
|
||||||
"version": "7.7.1",
|
"version": "7.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
||||||
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
|
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
|
||||||
|
"license": "ISC",
|
||||||
"bin": {
|
"bin": {
|
||||||
"semver": "bin/semver.js"
|
"semver": "bin/semver.js"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@
|
||||||
"promise-sequential": "^1.1.1",
|
"promise-sequential": "^1.1.1",
|
||||||
"queue-promise": "^2.2.1",
|
"queue-promise": "^2.2.1",
|
||||||
"request-promise": "^4.2.6",
|
"request-promise": "^4.2.6",
|
||||||
"semver": "^7.1.3",
|
"semver": "^7.7.1",
|
||||||
"serve-static": "^1.12.4",
|
"serve-static": "^1.12.4",
|
||||||
"talisman": "^0.20.0",
|
"talisman": "^0.20.0",
|
||||||
"telnyx": "^1.25.5",
|
"telnyx": "^1.25.5",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue