Skip to content

Commit

Permalink
fixed issues with node js client
Browse files Browse the repository at this point in the history
  • Loading branch information
jpswinski committed Jun 1, 2023
1 parent b4fa4bb commit 82c1131
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
16 changes: 8 additions & 8 deletions clients/nodejs/sliderule/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ function httpRequest(options, body) {
});

// Populate Body of Request (if provided)
if (typeof body != null) {
if (body != null) {
request.write(body);
}

Expand All @@ -401,20 +401,20 @@ exports.init = (config) => {
//
exports.source = (api, parm=null, stream=false) => {

// Build Body
let body = null
if (parm != null) {
body = JSON.stringify(parm);
}

// Setup Request Options
const options = {
host: sysConfig.organization && (sysConfig.organization + '.' + sysConfig.domain) || sysConfig.domain,
path: '/source/' + api,
method: stream && 'POST' || 'GET',
headers: {'Content-Type': 'application/json', 'Content-Length': body.length},
};

// Build Body
let body = null
if (parm != null) {
body = JSON.stringify(parm);
options["headers"] = {'Content-Type': 'application/json', 'Content-Length': body.length};
}

// Make API Request
return httpRequest(options, body);
}
Expand Down
10 changes: 7 additions & 3 deletions clients/nodejs/sliderule/tests/h5.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const sliderule = require('../../sliderule');

test('read icesat2 dataset using h5coro', () => {
return sliderule.core.h5().then(
result => result,
error => {throw new Error(error);}
return sliderule.core.h5("ancillary_data/atlas_sdp_gps_epoch", "ATL03_20181019065445_03150111_004_01.h5", "icesat2").then(
result => {
expect(result[0]).toBe(1198800018);
},
error => {
throw new Error(error);
}
);
});

12 changes: 8 additions & 4 deletions clients/nodejs/utils/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ sliderule.core.authenticate().then(
);
*/

/*
sliderule.core.h5("ancillary_data/atlas_sdp_gps_epoch", "ATL03_20181019065445_03150111_004_01.h5", "icesat2").then(
result => console.log("GPS Epoch: ", result[0]),
error => console.error(error)
);
*/

//let a = sliderule.core.source("definition", {"rectype" : "h5file"}).then(
// result => console.log(result),
// error => console.error(error)
//);
/*
let a = sliderule.core.source("definition", {"rectype" : "h5file"}).then(
result => console.log(result),
error => console.error(error)
);
*/

0 comments on commit 82c1131

Please sign in to comment.