mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Feat: introduce make-fetch-happen (#44)
This commit is contained in:
23
Build/lib/make-fetch-happen.ts
Normal file
23
Build/lib/make-fetch-happen.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import makeFetchHappen from 'make-fetch-happen';
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports -- type only
|
||||
export type { Response as NodeFetchResponse } from 'node-fetch';
|
||||
|
||||
const cachePath = path.resolve(__dirname, '../../.cache/__make_fetch_happen__');
|
||||
fs.mkdirSync(cachePath, { recursive: true });
|
||||
|
||||
export const $fetch = makeFetchHappen.defaults({
|
||||
cachePath,
|
||||
maxSockets: 32, /**
|
||||
* They said 15 is a good default that prevents knocking out others' routers,
|
||||
* I disagree. 32 is a good number.
|
||||
*/
|
||||
headers: {
|
||||
'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)'
|
||||
},
|
||||
retry: {
|
||||
retries: 5,
|
||||
randomize: true
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user