Ghost/core/server/lib/request.js
Hannah Wolfe 0fe8426f97
Renamed validation to validator + better public API
- renamed our internal validation library to "validator" - which is the same as the tool it wraps
- updated the public api so that validator methods are directly exposed
- this will make it a drop-in replacement for validator-js
- in turn, this allows us to pull this out into @tryghost/validator, and use our own wrapper instead of the 3rd party library
2021-06-15 15:32:36 +01:00

26 lines
745 B
JavaScript

const got = require('got');
const _ = require('lodash');
const validator = require('../data/validator');
const errors = require('@tryghost/errors');
const ghostVersion = require('./ghost-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);
};