Skip to content

Commit

Permalink
api config
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Jul 21, 2023
1 parent 29d4471 commit d774954
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/configs/api.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const helper = require('../utils/helper.util');

const api = {
enableCse: helper.setBool('SEARCH_API_ENABLE_CSE'),
enableLdap: helper.setBool('SEARCH_API_ENABLE_LDAP'),
enableUnit: helper.setBool('SEARCH_API_ENABLE_UNIT'),
enableGraphsearch: helper.setBool('SEARCH_API_ENABLE_GRAPHSEARCH')
};

module.exports = api;
15 changes: 15 additions & 0 deletions src/utils/helper.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ function permutations (arr) {
);
};

/**
* Convert an environment variable from string to boolean.
*
* @example
* const helper = require('../utils/helper.util');
* helper.setBool('SEARCH_API_ENABLE_CSE'); // => true
*
* @param {string} key A key of an environment variable.
* @returns {boolean} Return true if the env. variable is "true" or false.
*/
function setBool (key) {
return validateEnv(key).toLowerCase() === 'true';
}

/**
* Validate environment variables.
*
Expand All @@ -54,5 +68,6 @@ function validateEnv (key) {

module.exports = {
permutations,
setBool,
validateEnv
};

0 comments on commit d774954

Please sign in to comment.