2017-09-07 14:17:24 +03:00
|
|
|
var got = require('got'),
|
2017-12-12 00:47:46 +03:00
|
|
|
_ = require('lodash'),
|
2017-09-07 14:17:24 +03:00
|
|
|
validator = require('../data/validation').validator,
|
2019-01-28 19:01:34 +03:00
|
|
|
common = require('./common'),
|
|
|
|
ghostVersion = require('./ghost-version');
|
|
|
|
|
|
|
|
var defaultOptions = {
|
|
|
|
headers: {
|
|
|
|
'user-agent': 'Ghost/' + ghostVersion.original + ' (https://github.com/TryGhost/Ghost)'
|
|
|
|
}
|
|
|
|
};
|
2017-09-07 14:17:24 +03:00
|
|
|
|
|
|
|
module.exports = function request(url, options) {
|
|
|
|
if (_.isEmpty(url) || !validator.isURL(url)) {
|
2017-12-12 00:47:46 +03:00
|
|
|
return Promise.reject(new common.errors.InternalServerError({
|
2017-09-07 14:17:24 +03:00
|
|
|
message: 'URL empty or invalid.',
|
|
|
|
code: 'URL_MISSING_INVALID',
|
|
|
|
context: url
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2019-01-28 19:01:34 +03:00
|
|
|
var mergedOptions = _.merge({}, defaultOptions, options);
|
|
|
|
|
|
|
|
return got(url, mergedOptions);
|
2017-09-07 14:17:24 +03:00
|
|
|
};
|