@contentacms/contentajs
Version:
A nodejs server that proxies to Contenta CMS and holds custom code.
36 lines (29 loc) • 928 B
JavaScript
;
const config = require('config');
const got = require('got');
const Keyv = require('keyv');
const logger = require('pino')();
const pkg = require('../../package.json');
const activeApplicationCache = config.get('applicationCache.activePlugin');
const opts = config.get(`applicationCache.plugins.${activeApplicationCache}`);
const keyv = new Keyv(opts);
keyv.on('error', logger.error.bind(logger));
const defaults = {
headers: {
'user-agent': `${pkg.name}/${pkg.version} (https://github.com/contentacms/contentajs)`
},
json: true,
cache: keyv
};
/**
* Makes a request using got with some sensible defaults.
*
* @param {string} url
* The URL to make the HTTP request to.
* @param {Object} options
* An options object according to got.
*
* @return {Promise<any>}
* A promise of the response.
*/
module.exports = (url, options = {}) => got(url, Object.assign({}, defaults, options));