sepia-search-motore-di-rice.../server/helpers/requests.ts

18 lines
553 B
TypeScript

import * as Bluebird from 'bluebird'
import * as request from 'request'
function doRequest <T> (
requestOptions: request.CoreOptions & request.UriOptions
): Bluebird<{ response: request.RequestResponse, body: T }> {
if (!(requestOptions.headers)) requestOptions.headers = {}
requestOptions.headers['User-Agent'] = 'PeerTube indexer'
return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => {
request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body }))
})
}
export {
doRequest
}