upgraded express

This commit is contained in:
Josh Harvey 2016-05-11 23:44:29 +03:00
parent 8b0159d099
commit e41e5d7ac7
3 changed files with 17 additions and 15 deletions

View file

@ -3,6 +3,7 @@
var http = require('http') var http = require('http')
var https = require('https') var https = require('https')
var express = require('express') var express = require('express')
var bodyParser = require('body-parser')
var LamassuConfig = require('lamassu-config') var LamassuConfig = require('lamassu-config')
var routes = require('./routes') var routes = require('./routes')
var plugins = require('./plugins') var plugins = require('./plugins')
@ -45,7 +46,7 @@ module.exports = function (options) {
}) })
}) })
app.use(express.bodyParser()) app.use(bodyParser.json())
var authMiddleware var authMiddleware
@ -87,7 +88,7 @@ module.exports = function (options) {
if (options.mock) logger.info('In mock mode') if (options.mock) logger.info('In mock mode')
var localApp = express() var localApp = express()
localApp.use(express.bodyParser()) localApp.use(bodyParser.json())
var localServer = http.createServer(localApp) var localServer = http.createServer(localApp)
var localPort = 7070 var localPort = 7070

View file

@ -77,7 +77,7 @@ function poll (req, res) {
} catch (e) { } catch (e) {
if (e instanceof E.NoDataError) { if (e instanceof E.NoDataError) {
logger.debug(e) 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})) .then(code => res.json({code: code}))
.catch(err => { .catch(err => {
logger.error(err) logger.error(err)
if (err.name === 'BadNumberError') return res.send(410) if (err.name === 'BadNumberError') return res.sendStatus(410)
return res.send(500) return res.sendStatus(500)
}) })
} }
@ -243,7 +243,7 @@ function updatePhone (req, res) {
.then(code => res.json(200)) .then(code => res.json(200))
.catch(err => { .catch(err => {
logger.error(err) logger.error(err)
res.send(500) res.sendStatus(500)
}) })
} }
@ -252,7 +252,7 @@ function fetchPhoneTx (req, res) {
.then(r => res.json(r)) .then(r => res.json(r))
.catch(err => { .catch(err => {
logger.error(err) logger.error(err)
res.send(500) res.sendStatus(500)
}) })
} }
@ -261,20 +261,20 @@ function registerRedeem (req, res) {
.then(() => res.json({success: true})) .then(() => res.json({success: true}))
.catch(err => { .catch(err => {
logger.error(err) logger.error(err)
res.send(500) res.sendStatus(500)
}) })
} }
function waitForDispense (req, res) { function waitForDispense (req, res) {
return plugins.fetchTx(session(req)) return plugins.fetchTx(session(req))
.then(tx => { .then(tx => {
if (!tx) return res.send(404) if (!tx) return res.sendStatus(404)
if (tx.status === req.query.status) return res.send(304) if (tx.status === req.query.status) return res.sendStatus(304)
res.json({tx: tx}) res.json({tx: tx})
}) })
.catch(err => { .catch(err => {
logger.error(err) logger.error(err)
res.send(500) res.sendStatus(500)
}) })
} }
@ -284,7 +284,7 @@ function dispense (req, res) {
.then(() => res.json(200)) .then(() => res.json(200))
.catch(err => { .catch(err => {
logger.error(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) console.log('pid: %s, fingerprint: %s', pid, fingerprint)
if (!fingerprint || !pid) { if (!fingerprint || !pid) {
return res.send(400) return res.sendStatus(400)
} }
reboots[fingerprint] = pid reboots[fingerprint] = pid
res.send(200) res.sendStatus(200)
}) })
return app return app

View file

@ -11,9 +11,10 @@
"dependencies": { "dependencies": {
"async": "~0.2.9", "async": "~0.2.9",
"bignumber.js": "^2.3.0", "bignumber.js": "^2.3.0",
"body-parser": "^1.15.1",
"bunyan": "^1.8.1", "bunyan": "^1.8.1",
"chalk": "^1.1.3", "chalk": "^1.1.3",
"express": "~3.4.7", "express": "^4.13.4",
"inquirer": "^1.0.0", "inquirer": "^1.0.0",
"lamassu-bitcoinaverage": "~1.0.0", "lamassu-bitcoinaverage": "~1.0.0",
"lamassu-bitcoind": "^1.1.0", "lamassu-bitcoind": "^1.1.0",