From 035141c389d92709be630f67f4c8bdb32513f7fc Mon Sep 17 00:00:00 2001 From: joeuhren Date: Fri, 22 May 2020 12:01:02 -0600 Subject: [PATCH] All api end-points now return text values with HTTP header content-type 'text/plain' --- app.js | 6 ++++-- lib/nodeapi.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index f3cff14..83e88f5 100644 --- a/app.js +++ b/app.js @@ -63,7 +63,8 @@ app.use('/api', nodeapi.app); app.use('/', routes); app.use('/ext/getmoneysupply', function(req,res){ lib.get_supply(function(supply){ - res.send(' '+supply); + res.setHeader('content-type', 'text/plain'); + res.end(supply.toString()); }); }); @@ -87,7 +88,8 @@ app.use('/ext/getaddress/:hash', function(req,res){ app.use('/ext/getbalance/:hash', function(req,res){ db.get_address(req.params.hash, false, function(address){ if (address) { - res.send((address.balance / 100000000).toString().replace(/(^-+)/mg, '')); + res.setHeader('content-type', 'text/plain'); + res.end((address.balance / 100000000).toString().replace(/(^-+)/mg, '')); } else { res.send({ error: 'address not found.', hash: req.params.hash}) } diff --git a/lib/nodeapi.js b/lib/nodeapi.js index fd9b750..2d4459a 100644 --- a/lib/nodeapi.js +++ b/lib/nodeapi.js @@ -49,7 +49,8 @@ module.exports = function(){ res.json(response); } else{ - res.send(""+response); + res.setHeader('content-type', 'text/plain'); + res.end(response.toString()); } } });