diff --git a/lib/app.js b/lib/app.js index 71098dc7..02c119e9 100644 --- a/lib/app.js +++ b/lib/app.js @@ -3,6 +3,7 @@ var http = require('http') var https = require('https') var express = require('express') +var bodyParser = require('body-parser') var LamassuConfig = require('lamassu-config') var routes = require('./routes') var plugins = require('./plugins') @@ -45,7 +46,7 @@ module.exports = function (options) { }) }) - app.use(express.bodyParser()) + app.use(bodyParser.json()) var authMiddleware @@ -87,7 +88,7 @@ module.exports = function (options) { if (options.mock) logger.info('In mock mode') var localApp = express() - localApp.use(express.bodyParser()) + localApp.use(bodyParser.json()) var localServer = http.createServer(localApp) var localPort = 7070 diff --git a/lib/routes.js b/lib/routes.js index 3a7d7cf3..cf42874f 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -77,7 +77,7 @@ function poll (req, res) { } catch (e) { if (e instanceof E.NoDataError) { logger.debug(e) - return res.send(500) + return res.sendStatus(500) } } @@ -232,8 +232,8 @@ function phoneCode (req, res) { .then(code => res.json({code: code})) .catch(err => { logger.error(err) - if (err.name === 'BadNumberError') return res.send(410) - return res.send(500) + if (err.name === 'BadNumberError') return res.sendStatus(410) + return res.sendStatus(500) }) } @@ -243,7 +243,7 @@ function updatePhone (req, res) { .then(code => res.json(200)) .catch(err => { logger.error(err) - res.send(500) + res.sendStatus(500) }) } @@ -252,7 +252,7 @@ function fetchPhoneTx (req, res) { .then(r => res.json(r)) .catch(err => { logger.error(err) - res.send(500) + res.sendStatus(500) }) } @@ -261,20 +261,20 @@ function registerRedeem (req, res) { .then(() => res.json({success: true})) .catch(err => { logger.error(err) - res.send(500) + res.sendStatus(500) }) } function waitForDispense (req, res) { return plugins.fetchTx(session(req)) .then(tx => { - if (!tx) return res.send(404) - if (tx.status === req.query.status) return res.send(304) + if (!tx) return res.sendStatus(404) + if (tx.status === req.query.status) return res.sendStatus(304) res.json({tx: tx}) }) .catch(err => { logger.error(err) - res.send(500) + res.sendStatus(500) }) } @@ -284,7 +284,7 @@ function dispense (req, res) { .then(() => res.json(200)) .catch(err => { logger.error(err) - res.send(500) + res.sendStatus(500) }) } @@ -329,11 +329,11 @@ function init (localConfig) { console.log('pid: %s, fingerprint: %s', pid, fingerprint) if (!fingerprint || !pid) { - return res.send(400) + return res.sendStatus(400) } reboots[fingerprint] = pid - res.send(200) + res.sendStatus(200) }) return app diff --git a/package.json b/package.json index 78817775..fc0ef3f6 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,10 @@ "dependencies": { "async": "~0.2.9", "bignumber.js": "^2.3.0", + "body-parser": "^1.15.1", "bunyan": "^1.8.1", "chalk": "^1.1.3", - "express": "~3.4.7", + "express": "^4.13.4", "inquirer": "^1.0.0", "lamassu-bitcoinaverage": "~1.0.0", "lamassu-bitcoind": "^1.1.0",