diff options
author | mat <github@matdoes.dev> | 2022-05-30 12:48:48 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-05-30 12:48:48 -0500 |
commit | f8b1876203c6d0449e597bf9d9de4bdabf55b242 (patch) | |
tree | 72c2dd7679de28c3b50d19601135d1f215f52a2e /src/constants.ts | |
parent | 5777b24bbf1ccad2b4c897d8c3960b892405b7c0 (diff) | |
download | skyblock-api-f8b1876203c6d0449e597bf9d9de4bdabf55b242.tar.gz skyblock-api-f8b1876203c6d0449e597bf9d9de4bdabf55b242.tar.bz2 skyblock-api-f8b1876203c6d0449e597bf9d9de4bdabf55b242.zip |
Replace node-fetch with undici and bump deps
Diffstat (limited to 'src/constants.ts')
-rw-r--r-- | src/constants.ts | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/src/constants.ts b/src/constants.ts index 8143381..769eb7d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,17 +5,13 @@ // we have to do this so we can mock the function from the tests properly import * as constants from './constants.js' -import * as nodeFetch from 'node-fetch' import NodeCache from 'node-cache' import { debug } from './index.js' import { sleep } from './util.js' import Queue from 'queue-promise' -import fetch from 'node-fetch' -import { Agent } from 'https' +import { fetch } from 'undici' +import type { Response as UndiciResponse } from 'undici/types/fetch' -const httpsAgent = new Agent({ - keepAlive: true -}) const githubApiBase = 'https://api.github.com' const owner = 'skyblockstats' @@ -34,13 +30,12 @@ const queue = new Queue({ * @param headers The extra headers * @param json The JSON body, only applicable for some types of methods */ -async function fetchGithubApi(method: string, route: string, headers?: any, json?: any): Promise<nodeFetch.Response> { +async function fetchGithubApi(method: string, route: string, headers?: any, json?: any): Promise<UndiciResponse> { try { if (debug) console.debug('fetching github api', method, route) const data = await fetch( githubApiBase + route, { - agent: () => httpsAgent, body: json ? JSON.stringify(json) : undefined, method, headers: Object.assign({ |