ffffng/server/utils/urlBuilder.js

42 lines
945 B
JavaScript
Raw Normal View History

'use strict';
2018-12-17 22:49:54 +01:00
const _ = require('lodash')
const config = require('../config').config
function formUrl(route, queryParams) {
let url = config.server.baseUrl;
if (route || queryParams) {
url += '/#/';
}
if (route) {
url += route;
}
2018-12-17 22:49:54 +01:00
if (queryParams) {
url += '?';
url += _.join(
_.map(
queryParams,
function (value, key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
),
'&'
);
}
return url;
}
2018-12-17 22:49:54 +01:00
module.exports = {
editNodeUrl () {
return formUrl('update');
},
2018-12-17 22:49:54 +01:00
monitoringConfirmUrl (nodeSecrets) {
return formUrl('monitoring/confirm', { token: nodeSecrets.monitoringToken });
},
monitoringDisableUrl (nodeSecrets) {
return formUrl('monitoring/disable', { token: nodeSecrets.monitoringToken });
}
}