UNPKG

@contentacms/contentajs

Version:

A nodejs server that proxies to Contenta CMS and holds custom code.

45 lines (37 loc) 1.03 kB
"use strict"; 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) } }; /** * 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));