diff --git a/server/index.js b/server/index.js index 47b2141..6cf93ad 100644 --- a/server/index.js +++ b/server/index.js @@ -1,7 +1,7 @@ const Bcoin = require('./lib/node'); const config = require('./config'); const logger = require('./lib/logger'); -const Api = require('./lib/api'); +const Api = require('./lib/api').server; const db = require('./lib/db'); logger.log('debug', diff --git a/server/lib/api/index.js b/server/lib/api/index.js index 27692f6..c8aced1 100644 --- a/server/lib/api/index.js +++ b/server/lib/api/index.js @@ -14,6 +14,8 @@ app.use(bodyParser.json()); // Serve insight ui front end from root dir public folder app.use(express.static('../app/www', { maxage: '1w' })); +// Legacy UI - useful for 1:1 compares +// app.use(express.static('./public', { maxage: '1w' })); app.set('json spaces', config.api.json_spaces); @@ -37,4 +39,7 @@ app.use((req, res) => res.status(404).send({ // Socket server const server = require('http').Server(app); -module.exports = server; +module.exports = { + server, + api, +}; diff --git a/server/lib/api/transaction.js b/server/lib/api/transaction.js index ea0ef2b..a882ced 100644 --- a/server/lib/api/transaction.js +++ b/server/lib/api/transaction.js @@ -59,7 +59,6 @@ module.exports = function transactionAPI(router) { // /txs is overloaded. Next ver separate concerns // query by block // query by address - // last n txs - haha jk YOU 404 router.get('/txs', (req, res) => { const pageNum = parseInt(req.query.pageNum, 10) || 0; const rangeStart = pageNum * MAX_TXS; @@ -174,30 +173,29 @@ module.exports = function transactionAPI(router) { `/txs getTopTransactions ${err}`); return res.status(404).send(err); } - return res.json({ - txs: txs.map(tx => ({ - txid: tx.hash, - fees: tx.fee / 1e8, - size: tx.size, - confirmations: (height - tx.height) + 1, - valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8, - vin: tx.inputs.map(input => ({ - scriptSig: { - asm: input.script, - }, - addr: input.address, - value: input.value / 1e8, - })), - vout: tx.outputs.map(output => ({ - scriptPubKey: { - asm: output.script, - addresses: [output.address], - }, - value: output.value / 1e8, - })), - isCoinBase: tx.inputs[0].prevout.hash === '0000000000000000000000000000000000000000000000000000000000000000', + return res.send(txs.map(tx => ({ + txid: tx.hash, + fees: tx.fee / 1e8, + size: tx.size, + confirmations: (height - tx.height) + 1, + valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8, + vin: tx.inputs.map(input => ({ + scriptSig: { + asm: input.script, + }, + addr: input.address, + value: input.value / 1e8, })), - }); + vout: tx.outputs.map(output => ({ + scriptPubKey: { + asm: output.script, + addresses: [output.address], + }, + value: output.value / 1e8, + })), + isCoinBase: tx.inputs[0].prevout.hash === '0000000000000000000000000000000000000000000000000000000000000000', + })), + ); }); } });