lodash#defaults JavaScript Examples

The following examples show how to use lodash#defaults. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: web-api-utils.js    From ThreatMapper with Apache License 2.0 7 votes vote down vote up
/**
  * XHR wrapper. Applies a CSRF token (if it exists) and content-type to all requests.
  * Any opts that get passed in will override the defaults.
  */
export function doRequest(opts) {
  const config = defaults(opts, {
    contentType: 'application/json',
    type: 'json'
  });
  if (csrfToken) {
    config.headers = Object.assign({}, config.headers, { 'X-CSRF-Token': csrfToken });
  }

  return reqwest(config);
}
Example #2
Source File: web-api-utils.js    From ThreatMapper with Apache License 2.0 7 votes vote down vote up
/**
 * XHR wrapper. Applies a CSRF token (if it exists) and content-type to all requests.
 * Any opts that get passed in will override the defaults.
 */
export function doRequest(opts) {
  const config = defaults(opts, {
    contentType: 'application/json',
    type: 'json',
  });
  if (csrfToken) {
    config.headers = { ...config.headers, 'X-CSRF-Token': csrfToken };
  }
  if (!config.headers) {
    config.headers = {
      'deepfence-key': localStorage.getItem('dfApiKey'),
    };
  } else if (!('deepfence-key' in config.headers)) {
    config.headers['deepfence-key'] = localStorage.getItem('dfApiKey');
  }
  return reqwest(config);
}