const fs = require('fs');
require('node-zip');
-function _request(context, method, path, data, isBinary=false, prefix='onboarding') {
- let server = context.server + '/' + context.prefix[prefix];
+function _request(context, method, path, data, isBinary=false, type='onboarding') {
+ let server = context.getUrlForType(type);
let options = {
method: method,
url: server + path,
- headers: context.headers
+ headers: context.headers[type]
};
+ console.log('--> Calling REST ' + options.method +' url: ' + options.url);
+
return new Promise(function (resolve, reject) {
if (method === 'POST' || method === 'PUT') {
if (isBinary) {
});
}
-function download(context, path, filePath, callback){
- let options = {
+function download(context, path, filePath, callback, type='onboarding') {
+ let server = context.getUrlForType(type);
+ let options = {
method: 'GET',
- url: context.onboarding_server + path,
- headers: context.headers
+ url: server + path,
+ headers: context.headers[type]
};
- var file = fs.createWriteStream(filePath);
+ console.log('--> Calling REST download url: ' + options.url);
+
+ var file = fs.createWriteStream(filePath);
var r = request(options).pipe(file);
r.on('error', function (err) {
console.log(err);