title: Cannot read property of “pool” undefined
body: <p>I want to switch my pool server from http to https and my charts on my website are not working.</p>
  
  <p>This is what i get...</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'pool' of undefined<br>
    at /home/"user"/pool/lib/charts.js:149:30<br>
    at ClientRequest. (/home/"user"/pool/lib/apiInterfaces.js:39:9)<br>
    at ClientRequest.EventEmitter.emit (events.js:95:17)<br>
    at Socket.socketCloseListener (http.js:1522:9)<br>
    at Socket.EventEmitter.emit (events.js:117:20)<br>
    at TCP.close (net.js:466:12)</p>
  </blockquote>
  
  <p>chart.js</p>
  
  <pre><code>var fs = require('fs');
  var async = require('async');
  var http = require('https');
  var apiInterfaces = require('./apiInterfaces.js')(config.daemon, config.wallet, config.api);
  
  var logSystem = 'charts';
  require('./exceptionWriter.js')(logSystem);
  
  log('info', logSystem, 'Started');
  
  function startDataCollectors() {
      async.each(Object.keys(config.charts.pool), function(chartName) {
          var settings = config.charts.pool[chartName];
          if(settings.enabled) {
              setInterval(function() {
                  collectPoolStatWithInterval(chartName, settings);
              }, settings.updateInterval * 1000);
          }
      });
  
      var settings = config.charts.user.hashrate;
      if(settings.enabled) {
          setInterval(function() {
              collectUsersHashrate('hashrate', settings);
          }, settings.updateInterval * 1000)
      }
  }
  
  function getChartDataFromRedis(chartName, callback) {
      redisClient.get(getStatsRedisKey(chartName), function(error, data) {
          callback(data ? JSON.parse(data) : []);
      });
  }
  
  function getUserHashrateChartData(address, callback) {
      getChartDataFromRedis('hashrate:' + address, callback);
  }
  
  function convertPaymentsDataToChart(paymentsData) {
      var data = [];
      if(paymentsData &amp;&amp; paymentsData.length) {
          for(var i = 0; paymentsData[i]; i += 2) {
              data.unshift([+paymentsData[i + 1], paymentsData[i].split(':')[1]]);
          }
      }
      return data;
  }
  
  function getUserChartsData(address, paymentsData, callback) {
      var stats = {};
      var chartsFuncs = {
          hashrate: function(callback) {
              getUserHashrateChartData(address, function(data) {
                  callback(null, data);
              });
          },
  
          payments: function(callback) {
              callback(null, convertPaymentsDataToChart(paymentsData));
          }
      };
      for(var chartName in chartsFuncs) {
          if(!config.charts.user[chartName].enabled) {
              delete chartsFuncs[chartName];
          }
      }
      async.parallel(chartsFuncs, callback);
  }
  
  function getStatsRedisKey(chartName) {
      return config.coin + ':charts:' + chartName;
  }
  
  var chartStatFuncs = {
      hashrate: getPoolHashrate,
      workers: getPoolWorkers,
      difficulty: getNetworkDifficulty,
      price: getCoinPrice,
      profit: getCoinProfit
  };
  
  var statValueHandler = {
      avg: function(set, value) {
          set[1] = (set[1] * set[2] + value) / (set[2] + 1);
      },
      avgRound: function(set, value) {
          statValueHandler.avg(set, value);
          set[1] = Math.round(set[1]);
      },
      max: function(set, value) {
          if(value &gt; set[1]) {
              set[1] = value;
          }
      }
  };
  
  var preSaveFunctions = {
      hashrate: statValueHandler.avgRound,
      workers: statValueHandler.max,
      difficulty: statValueHandler.avgRound,
      price: statValueHandler.avg,
      profit: statValueHandler.avg
  };
  
  function storeCollectedValues(chartName, values, settings) {
      for(var i in values) {
          storeCollectedValue(chartName + ':' + i, values[i], settings);
      }
  }
  
  function storeCollectedValue(chartName, value, settings) {
      var now = new Date() / 1000 | 0;
      getChartDataFromRedis(chartName, function(sets) {
          var lastSet = sets[sets.length - 1]; // [time, avgValue, updatesCount]
          if(!lastSet || now - lastSet[0] &gt; settings.stepInterval) {
              lastSet = [now, value, 1];
              sets.push(lastSet);
              while(now - sets[0][0] &gt; settings.maximumPeriod) { // clear old sets
                  sets.shift();
              }
          }
          else {
              preSaveFunctions[chartName]
                  ? preSaveFunctions[chartName](lastSet, value)
                  : statValueHandler.avgRound(lastSet, value);
              lastSet[2]++;
          }
          redisClient.set(getStatsRedisKey(chartName), JSON.stringify(sets));
          log('info', logSystem, chartName + ' chart collected value ' + value + '. Total sets count ' + sets.length);
      });
  }
  
  function collectPoolStatWithInterval(chartName, settings) {
      async.waterfall([
          chartStatFuncs[chartName],
          function(value, callback) {
              storeCollectedValue(chartName, value, settings, callback);
          }
      ]);
  }
  
  function getPoolStats(callback) {
      apiInterfaces.pool('/stats', callback);
  }
  
  function getPoolHashrate(callback) {
      getPoolStats(function(error, stats) {
          callback(error, stats.pool ? Math.round(stats.pool.hashrate) : null);
      });
  }
  
  function getPoolWorkers(callback) {
      getPoolStats(function(error, stats) {
          callback(error, stats.pool ? stats.pool.miners : null);
      });
  }
  
  function getNetworkDifficulty(callback) {
      getPoolStats(function(error, stats) {
          callback(error, stats.pool ? stats.network.difficulty : null);
      });
  }
  
  function getUsersHashrates(callback) {
      apiInterfaces.pool('/miners_hashrate', function(error, data) {
          callback(data.minersHashrate);
      });
  }
  
  function collectUsersHashrate(chartName, settings) {
      var redisBaseKey = getStatsRedisKey(chartName) + ':';
      redisClient.keys(redisBaseKey + '*', function(keys) {
          var hashrates = {};
          for(var i in keys) {
              hashrates[keys[i].substr(keys[i].length)] = 0;
          }
          getUsersHashrates(function(newHashrates) {
              for(var address in newHashrates) {
                  hashrates[address] = newHashrates[address];
              }
              storeCollectedValues(chartName, hashrates, settings);
          });
      });
  }
  
  function getCoinPrice(callback) {
      apiInterfaces.jsonHttpRequest('www.cryptonator.com', 443, '', function(error, response) {
          callback(response.error ? response.error : error, response.success ? +response.ticker.price : null);
      }, '/api/ticker/' + config.symbol.toLowerCase() + '-usd');
  }
  
  function getCoinProfit(callback) {
      getCoinPrice(function(error, price) {
          if(error) {
              callback(error);
              return;
          }
          getPoolStats(function(error, stats) {
              if(error) {
                  callback(error);
                  return;
              }
              callback(null, stats.network.reward * price / stats.network.difficulty / config.coinUnits);
          });
      });
  }
  
  function getPoolChartsData(callback) {
      var chartsNames = [];
      var redisKeys = [];
      for(var chartName in config.charts.pool) {
          if(config.charts.pool[chartName].enabled) {
              chartsNames.push(chartName);
              redisKeys.push(getStatsRedisKey(chartName));
          }
      }
      if(redisKeys.length) {
          redisClient.mget(redisKeys, function(error, data) {
              var stats = {};
              if(data) {
                  for(var i in data) {
                      if(data[i]) {
                          stats[chartsNames[i]] = JSON.parse(data[i]);
                      }
                  }
              }
              callback(error, stats);
          });
      }
      else {
          callback(null, {});
      }
  }
  
  module.exports = {
      startDataCollectors: startDataCollectors,
      getUserChartsData: getUserChartsData,
      getPoolChartsData: getPoolChartsData
  };
  </code></pre>
  
  <p>apiInterfaces.js</p>
  
  <pre><code>var http = require('http');
  var https = require('https');
  
  function jsonHttpRequest(host, port, data, callback, path){
      path = path || '/json_rpc';
  
      var options = {
          hostname: host,
          port: port,
          path: path,
          method: data ? 'POST' : 'GET',
          headers: {
              'Content-Length': data.length,
              'Content-Type': 'application/json',
              'Accept': 'application/json'
          }
      };
  
      var req = (port == 443 ? https : http).request(options, function(res){
          var replyData = '';
          res.setEncoding('utf8');
          res.on('data', function(chunk){
              replyData += chunk;
          });
          res.on('end', function(){
              var replyJson;
              try{
                  replyJson = JSON.parse(replyData);
              }
              catch(e){
                  callback(e);
                  return;
              }
              callback(null, replyJson);
          });
      });
  
      req.on('error', function(e){
          callback(e);
      });
  
      req.end(data);
  }
  
  function rpc(host, port, method, params, callback){
  
      var data = JSON.stringify({
          id: "0",
          jsonrpc: "2.0",
          method: method,
          params: params
      });
      jsonHttpRequest(host, port, data, function(error, replyJson){
          if (error){
              callback(error);
              return;
          }
          callback(replyJson.error, replyJson.result)
      });
  }
  
  function batchRpc(host, port, array, callback){
      var rpcArray = [];
      for (var i = 0; i &lt; array.length; i++){
          rpcArray.push({
              id: i.toString(),
              jsonrpc: "2.0",
              method: array[i][0],
              params: array[i][1]
          });
      }
      var data = JSON.stringify(rpcArray);
      jsonHttpRequest(host, port, data, callback);
  }
  
  
  module.exports = function(daemonConfig, walletConfig, poolApiConfig){
      return {
          batchRpcDaemon: function(batchArray, callback){
              batchRpc(daemonConfig.host, daemonConfig.port, batchArray, callback);
          },
          rpcDaemon: function(method, params, callback){
              rpc(daemonConfig.host, daemonConfig.port, method, params, callback);
          },
          rpcWallet: function(method, params, callback){
              rpc(walletConfig.host, walletConfig.port, method, params, callback);
          },
          pool: function(method, callback){
              jsonHttpRequest('127.0.0.1', poolApiConfig.port, '', callback, method);
          },
          jsonHttpRequest: jsonHttpRequest
      }
  };
  </code></pre>