Skip to content

Commit

Permalink
[export] use internal request processor instead of making localhost r…
Browse files Browse the repository at this point in the history
…equests
  • Loading branch information
ar2rsawseen committed Apr 1, 2021
1 parent efa05fe commit bd1a339
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [configs] fix refreshing value when updating config
* [config] subdirectory cases for localhost calls
* [crashes] updated app version column header
* [export] use internal request processor instead of localhost for request exports
* [logger] remove sdk mismatch warning as they should be fully cross compatible
* [populator] add populator tag to all generated users
* [push] batched sent messages deletion
Expand All @@ -22,6 +23,7 @@
* [sources] fixed direct calculation logic
* [star-rating] feedback sticker style bug fixed
* [views] fix view postprocessing with dots in names
* [views] fixed view export file name
* [views] show view names in graph tooltips

**Enterprise fixes**
Expand Down
61 changes: 26 additions & 35 deletions api/parts/data/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ var exports = {},
common = require('./../../utils/common.js'),
moment = require('moment-timezone'),
plugin = require('./../../../plugins/pluginManager.js'),
countlyConfig = require("../../../frontend/express/config.js"),
json2csv = require('json2csv'),
json2xls = require('json2xls'),
request = require("request");
json2xls = require('json2xls');

//npm install node-xlsx-stream !!!!!
var xlsx = require("node-xlsx-stream");
Expand Down Expand Up @@ -483,44 +481,37 @@ exports.fromRequest = function(options) {
if (!options.path.startsWith("/")) {
options.path = "/" + options.path;
}
var opts = {
uri: "http://" + (process.env.COUNTLY_CONFIG_HOSTNAME || "localhost") + (countlyConfig.path || "") + options.path,
method: options.method || 'POST',
json: options.data || {},
strictSSL: false
};
options.filename = options.filename || options.path.replace(/\//g, "_") + "_on_" + moment().format("DD-MMM-YYYY");

/**
* Make request to get data
*/
function makeRequest() {
request(opts, function(error, response, body) {
//we got a redirect, we need to follow it
if (response && response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
opts.uri = response.headers.location;
makeRequest();
}
else {
var data = [];
try {
if (options.prop) {
var path = options.prop.split(".");
for (var i = 0; i < path.length; i++) {
body = body[path[i]];
}
//creating request context
var params = {
//providing data in request object
'req': {
url: options.path,
body: options.data || {},
method: "export"
},
//adding custom processing for API responses
'APICallback': function(err, body) {
var data = [];
try {
if (options.prop) {
var path = options.prop.split(".");
for (var i = 0; i < path.length; i++) {
body = body[path[i]];
}
data = body;
}
catch (ex) {
data = [];
}
exports.fromData(data, options);
data = body;
}
});
}
catch (ex) {
data = [];
}
exports.fromData(data, options);
}
};

makeRequest();
//processing request
common.processRequest(params);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/views/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ window.ViewsView = countlyView.extend({
app_id: countlyCommon.ACTIVE_APP_ID,
path: requestPath,
method: "GET",
filename: "Systemlogs_on_" + moment().format("DD-MMM-YYYY"),
filename: "Views_on_" + moment().format("DD-MMM-YYYY"),
prop: ['aaData']
};
return apiQueryData;
Expand Down

0 comments on commit bd1a339

Please sign in to comment.