Update api.js

Set `Content-Type: application/json` on api requests. This may help with browser compatibility and also allows browsers to render the json visually when directly browsing the api.
This commit is contained in:
hellcatz 2017-08-30 17:27:15 -07:00 committed by GitHub
parent 5e1301406e
commit e2af3372dd
1 changed files with 4 additions and 0 deletions

View File

@ -15,9 +15,11 @@ module.exports = function(logger, portalConfig, poolConfigs){
switch(req.params.method){
case 'stats':
res.header('Content-Type', 'application/json');
res.end(portalStats.statsString);
return;
case 'pool_stats':
res.header('Content-Type', 'application/json');
res.end(JSON.stringify(portalStats.statPoolHistory));
return;
case 'payments':
@ -25,9 +27,11 @@ module.exports = function(logger, portalConfig, poolConfigs){
for(var pool in portalStats.stats.pools) {
poolBlocks.push({name: pool, pending: portalStats.stats.pools[pool].pending, payments: portalStats.stats.pools[pool].payments});
}
res.header('Content-Type', 'application/json');
res.end(JSON.stringify(poolBlocks));
return;
case 'worker_stats':
res.header('Content-Type', 'application/json');
if (req.url.indexOf("?")>0) {
var url_parms = req.url.split("?");
if (url_parms.length > 0) {