mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
24332c3d24
no issue Part of the effort to break up the Ghost codebase into smaller, decoupled modules.
26 lines
749 B
JavaScript
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);
|
|
};
|