How to use the config.util function in config

To help you get started, we’ve selected a few config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / addons-frontend / tests / unit / helpers.js View on Github external
export const getFakeConfig = (
  params = {},
  { allowUnknownKeys = false } = {},
) => {
  for (const key of Object.keys(params)) {
    if (!config.has(key) && !allowUnknownKeys) {
      // This will help alert us when a test accidentally relies
      // on an invalid config key.
      throw new Error(
        `Cannot set a fake value for "${key}"; this key is invalid`,
      );
    }
  }
  return Object.assign(config.util.cloneDeep(config), params);
};
github joeferner / redis-commander / lib / util.js View on Github external
// validation of numbers at connections specific settings
  for (let index = 0; index < c.get('connections').length; ++index) {
    convertNumbers('connections.' + index + '.dbIndex');
    validateNumbers('connections.' + index + '.dbIndex', true, 0, Number.MAX_VALUE); // we do not know real server config, allow max...

    // check - port needs to be defined for "normal" redis, ignored for sentinel
    let sentinelsKey = 'connections.' + index + '.sentinels';
    if (c.has(sentinelsKey) && c.get(sentinelsKey)) {
      try {
        c.util.setPath(c, sentinelsKey.split('.'), parseRedisSentinel(sentinelsKey, c.get(sentinelsKey)));
      }
      catch (e) {
        hasError(e.message);
      }
      let groupName = 'connections.' + index + '.sentinelName';
      if (!c.has(groupName)) c.util.setPath(c, groupName.split('.'), c.get('redis.defaultSentinelGroup'));
    }
    else {
      convertNumbers('connections.' + index + '.port');
      validateNumbers('connections.' + index + '.port', true, 1, 65535);
    }

    // special case tls, can either be a boolean or object or stringified JSON
    let tlsKey = 'connections.' + index + '.tls';
    if (c.has(tlsKey)) {
      let tlsProp = c.get(tlsKey);
      switch (typeof tlsProp) {
        case 'boolean':
          break;
        case 'object':
          break;
        case 'number':
github contentacms / contentajs / src / helpers / app.js View on Github external
module.exports = async (cmsMeta: Object) => {
  const app = express();
  app.disable('x-powered-by');

  // Enable etags.
  app.enable('etag');
  app.set('etag', 'strong');
  const jsonApiPrefix = _.get(cmsMeta, 'jsonApiPrefix', '/jsonapi');
  const jsonApiPaths = JSON.parse(_.get(cmsMeta, 'jsonApiPaths', '[]'));
  const cmsHost = config.get('cms.host');

  // Set the global agent options
  const agentOptions = config.util.toObject(config.get('cms.httpAgent'));
  Object.keys(agentOptions).forEach(key => {
    _.set(httpGlobalAgent, [key], agentOptions[key]);
    _.set(httpsGlobalAgent, [key], agentOptions[key]);
  });

  const corsHandler = cors(config.util.toObject(config.get('cors')));
  app.use(corsHandler);
  // Adds support for preflight OPTIONS requests on all routes.
  app.options('*', corsHandler);

  // Initialize the request object with valuable information.
  app.use(copyToRequestObject({ jsonApiPrefix, jsonApiPaths, cmsHost }));

  // Healthcheck is a special endpoint used for application monitoring.
  app.get('/healthcheck', healthcheck);
github contentacms / contentajs / src / helpers / got.js View on Github external
// @flow

import type { ObjectLiteral } from '../../flow/types/common';
import type { GotResponse } from '../../flow/types/got';

const config = require('config');
const got = require('got');
const { Agent: HttpAgent } = require('http');
const { Agent: HttpsAgent } = require('https');
const pkg = require('../../package.json');

const keyv = require('./keyvInstance');

const agentOptions = config.util.toObject(config.get('got.httpAgent'));

const defaults = {
  headers: {
    'user-agent': `${pkg.name}/${pkg.version} (https://github.com/contentacms/contentajs)`,
  },
  json: true,
  cache: keyv,
  // Override the global agent options, since that is tuned for
  // express-http-proxy.
  agents: {
    http: new HttpAgent(agentOptions),
    https: new HttpsAgent(agentOptions),
  },
};

/**
github joeferner / redis-commander / bin / redis-commander.js View on Github external
myUtils.getDeprecatedConfig(function(err, oldConfig) {
      // old config only contains some ui parameters or connection definitions
      config.ui = config.util.extendDeep(config.ui, oldConfig.ui);
      if (Array.isArray(oldConfig.connections) && oldConfig.connections.length > 0) {
        oldConfig.connections.forEach(function(cfg) {
          if (!myUtils.containsConnection(config.connections, cfg)) {
            config.connections.push(cfg);
          }
        });
      }
      startAllConnections();
    });
  }
github badges / shields / scripts / badge-cli.js View on Github external
'use strict'

const { URL } = require('url')
const config = require('config').util.toObject()
const got = require('got')
const emojic = require('emojic')
const Server = require('../core/server/server')
const trace = require('../core/base-service/trace')

function normalizeBadgeUrl(url) {
  // Provide a base URL in order to accept fragments.
  const { pathname, searchParams } = new URL(url, 'http://example.com')
  const newPath = pathname.replace('.svg', '.json')
  return `${newPath}?${searchParams.toString()}`
}

async function traceBadge(badgeUrl) {
  const server = new Server(config)
  await server.start()
  const { body } = await got(
github brave / sync / server / index.js View on Github external
app.post('/:userId/credentials', cors({
  origin: '*'
}))

const UsersRouter = require('./users.js')
app.use('/', UsersRouter)

// Exception handling. The Sentry error handler must be before any other error middleware.
if (Config.sentryUrl) {
  app.use(raven.middleware.express.errorHandler(Config.sentryUrl))
  app.use(ravenOnError)
}

app.listen(Config.port)

Util.logger.info(`NODE_ENV: ${Config.util.getEnv('NODE_ENV')}`)
Util.logger.info(`sync server up on localhost:${Config.port}`)
github ozum / sequelize-pg-generator / lib / index.js View on Github external
}

    var customConfigFile, customConfig,
        defaultConfig       = require('../config/default.js');

    options = options || {};

    if (options.config) {
        customConfigFile    = options.config.charAt(0) === '/' || options.config.charAt(0) === '\\' ? options.config : path.join(process.cwd(), options.config); // Absolute or relative
        customConfig        = require(customConfigFile);
    }

    delete options.config;

    // Combine configs and override lower priority configs.
    config.util.extendDeep(config, defaultConfig, customConfig || {}, { "sequelize-pg-generator": options });
}
github turt2live / matrix-dimension / src / integration / index.js View on Github external
if (!configs[file]) configs[file] = {};
        configs[file]["defaults"] = config.util.parseFile(path.join(searchPath, file)) || {};
    }
}

var keys = _.keys(configs);
log.info("Integrations", "Discovered " + keys.length + " integrations. Parsing definitions...");

var linear = [];
var byUserId = {};
var byType = {};

for (var key of keys) {
    log.info("Integrations", "Preparing " + key);
    if (!configs[key].defaults) configs[key].defaults = {};
    var merged = config.util.extendDeep(configs[key].defaults, configs[key].alt);
    if (!merged['enabled']) {
        log.warn("Integrations", "Integration " + key + " is not enabled - skipping");
        continue;
    }

    var factory = IntegrationImpl.getFactory(merged);
    if (!factory) {
        log.warn("Integrations", "Integration " + key + " does not have an associated factory - skipping");
        continue;
    }
    try {
        factory.validateConfig(merged);
    } catch (err) {
        log.error("Integrations", "Error while validating integration " + key + " - skipping");
        log.error("Integrations", err);
        continue;
github Codigami / hapi-starter-kit / index.js View on Github external
return server.start((err) => {
        if (!err) {
          logger.info(`server started at port: ${config.get('app.port')} with env: ${config.util.getEnv('NODE_ENV')}`)
          return resolve()
        }
        return reject(err)
      })
    })