Skip to content

Commit

Permalink
Merge pull request #135 from koopjs/feature/134
Browse files Browse the repository at this point in the history
for #134: added "serviceUrl" to json response
  • Loading branch information
jkerr5 authored Nov 9, 2018
2 parents 2e4ed96 + 255eef2 commit 2c25a93
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/ml-modules/services/KoopSearchServices.sjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';


const koopConfigUri = '/koop/config.json';
const collFeatureServices = 'http://marklogic.com/feature-services';

function get(context, params) {
Expand All @@ -16,13 +17,33 @@ function get(context, params) {
}
}

function getKoopConfig() {
// could be cached
return cts.doc(koopConfigUri).toObject();
}

function getFeatureServiceUrl(serviceName) {
let config = getKoopConfig()
return fn.concat(
config.ssl ? 'https' : 'http',
'://',
config.host,
':',
config.port,
'/marklogic/',
serviceName,
'/FeatureServer'
);
}

function getSearchServices() {
let serviceDocs = cts.search(cts.collectionQuery(collFeatureServices));
let searchServices = [];
for (var serviceDoc of serviceDocs) {
for (var searchNode of serviceDoc.xpath('./search/*')) {
var searchObj = searchNode.toObject();
searchObj.serviceName = serviceDoc.xpath('./info/name').valueOf();
searchObj.serviceUrl = getFeatureServiceUrl(searchObj.serviceName);
searchObj.name = searchNode.xpath('./fn:name()').valueOf();
searchServices.push(searchObj);
}
Expand Down

0 comments on commit 2c25a93

Please sign in to comment.