Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const create = () => got.create({
options: got.mergeOptions(got.defaults.options, {
json: true,
token: process.env.GITHUB_TOKEN,
baseUrl: process.env.GITHUB_ENDPOINT || 'https://api.github.com',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'https://github.com/sindresorhus/gh-got'
}
}),
methods: got.defaults.methods,
handler: (options, next) => {
if (options.token) {
options.headers.authorization = options.headers.authorization || `token ${options.token}`;
}
if (options.stream) {
return next(options);
}
// TODO: Use async/await here when Got supports the `handler` being an async function
return next(options)
.then(response => { // eslint-disable-line promise/prefer-await-to-then
response.rateLimit = getRateLimit(response);
return response;
})
export function createBaseClient() {
return got.create({
options: got.mergeOptions(got.defaults.options, { json: true }),
methods: got.defaults.methods,
handler: requestLogger,
});
}