From 762ac618d35f31daa1f58026714332bd40339d7d Mon Sep 17 00:00:00 2001 From: siiky Date: Thu, 28 Nov 2024 11:30:35 +0000 Subject: [PATCH 1/3] refactor: don't send transactions' `expired` field --- lib/tx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tx.js b/lib/tx.js index 92e1dea6a..4a1d9b3c4 100644 --- a/lib/tx.js +++ b/lib/tx.js @@ -69,7 +69,7 @@ function cancel (txId) { } function customerHistory (customerId, thresholdDays) { - const sql = `SELECT * FROM ( + const sql = `SELECT ch.id, ch.created, ch.fiat, ch.direction FROM ( SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction, ((NOT txIn.send_confirmed) AND (txIn.created <= now() - interval $3)) AS expired FROM cash_in_txs txIn From 41e24d903948b4746e910c1ed5850378538c67aa Mon Sep 17 00:00:00 2001 From: siiky Date: Thu, 28 Nov 2024 13:01:09 +0000 Subject: [PATCH 2/3] feat: add read/written bytes from/to request/response Based on `count-response-size-middleware`. --- lib/middlewares/addRWBytes.js | 15 +++++++++++++++ lib/routes.js | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/middlewares/addRWBytes.js diff --git a/lib/middlewares/addRWBytes.js b/lib/middlewares/addRWBytes.js new file mode 100644 index 000000000..46a792756 --- /dev/null +++ b/lib/middlewares/addRWBytes.js @@ -0,0 +1,15 @@ +const addRWBytes = () => (req, res, next) => { + const handle = () => { + res.removeListener('finish', handle) + res.removeListener('close', handle) + res.bytesRead = req.connection.bytesRead + res.bytesWritten = req.connection.bytesWritten + } + + res.on('finish', handle) + res.on('close', handle) + + next() +} + +module.exports = addRWBytes diff --git a/lib/routes.js b/lib/routes.js index 6248fc8e0..0d0cb5d00 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -7,10 +7,11 @@ const nocache = require('nocache') const logger = require('./logger') +const addRWBytes = require('./middlewares/addRWBytes') const authorize = require('./middlewares/authorize') +const computeSchema = require('./middlewares/compute-schema') const errorHandler = require('./middlewares/errorHandler') const filterOldRequests = require('./middlewares/filterOldRequests') -const computeSchema = require('./middlewares/compute-schema') const findOperatorId = require('./middlewares/operatorId') const populateDeviceId = require('./middlewares/populateDeviceId') const populateSettings = require('./middlewares/populateSettings') @@ -50,6 +51,7 @@ const configRequiredRoutes = [ ] // middleware setup +app.use(addRWBytes()) app.use(compression({ threshold: 500 })) app.use(helmet()) app.use(nocache()) From 9d4808a5ff127132ba2a4269446c98ee94cd2142 Mon Sep 17 00:00:00 2001 From: siiky Date: Thu, 28 Nov 2024 13:01:54 +0000 Subject: [PATCH 3/3] feat: add read/written bytes to logs --- lib/routes.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/routes.js b/lib/routes.js index 0d0cb5d00..e6654121a 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -56,7 +56,10 @@ app.use(compression({ threshold: 500 })) app.use(helmet()) app.use(nocache()) app.use(express.json({ limit: '2mb' })) -app.use(morgan(':method :url :status :response-time ms -- :req[content-length]/:res[content-length] b', { stream: logger.stream })) + +morgan.token('bytesRead', (_req, res) => res.bytesRead) +morgan.token('bytesWritten', (_req, res) => res.bytesWritten) +app.use(morgan(':method :url :status :response-time ms -- :bytesRead/:bytesWritten B', { stream: logger.stream })) // app /pair and /ca routes app.use('/', pairingRoutes)