Ghost/core/server/lib/request.js
Sam Lord 24332c3d24 Replaced ghost-version.js with @tryghost/version
no issue
Part of the effort to break up the Ghost codebase into smaller, decoupled modules.
2021-06-16 13:16:15 +01:00

26 lines
749 B
JavaScript

const got = require('got');
const _ = require('lodash');
const validator = require('@tryghost/validator');
const errors = require('@tryghost/errors');
const ghostVersion = require('@tryghost/version');
const defaultOptions = {
headers: {
'user-agent': 'Ghost/' + ghostVersion.original + ' (https://github.com/TryGhost/Ghost)'
}
};
module.exports = function request(url, options) {
if (_.isEmpty(url) || !validator.isURL(url)) {
return Promise.reject(new errors.InternalServerError({
message: 'URL empty or invalid.',
code: 'URL_MISSING_INVALID',
context: url
}));
}
const mergedOptions = _.merge({}, defaultOptions, options);
return got(url, mergedOptions);
};