make-fetch-happen.ts 727 B

1234567891011121314151617181920212223
  1. import path from 'node:path';
  2. import fs from 'node:fs';
  3. import makeFetchHappen from 'make-fetch-happen';
  4. // eslint-disable-next-line @typescript-eslint/no-restricted-imports -- type only
  5. export type { Response as NodeFetchResponse } from 'node-fetch';
  6. const cachePath = path.resolve(__dirname, '../../.cache/__make_fetch_happen__');
  7. fs.mkdirSync(cachePath, { recursive: true });
  8. export const $fetch = makeFetchHappen.defaults({
  9. cachePath,
  10. maxSockets: 32, /**
  11. * They said 15 is a good default that prevents knocking out others' routers,
  12. * I disagree. 32 is a good number.
  13. */
  14. headers: {
  15. 'User-Agent': 'curl/8.9.1 (https://github.com/SukkaW/Surge)'
  16. },
  17. retry: {
  18. retries: 5,
  19. randomize: true
  20. }
  21. });