mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
The two wrappers (frontend/utils/fetch-with-timeout.js and common/fetch-upstream.js) were ~95% identical — same AbortController + setTimeout pattern, same caller-signal chaining, differing only in default timeout (5s vs 8s) and which half of the app imported them. Their tests were word-for-word duplicates too. Consolidate to common/fetch-with-timeout.js with two named exports: - fetchWithTimeout(url, init) — 5s default (front-end use) - fetchUpstream(url, init) — 8s preset around fetchWithTimeout (back-end) - frontend/utils/fetch-with-timeout.js becomes a thin re-export of the common module (same pattern we use for valid-ip.js). Front-end imports don't change. - All 12 back-end handler imports move from './common/fetch-upstream.js' to './common/fetch-with-timeout.js'. - tests/fetch-upstream.test.js is deleted; tests/fetch-with-timeout.test.js now covers both exports (10 cases total). - common/fetch-upstream.js deleted. Net: -1 file, -130 lines of duplicate code & tests; single source of truth for the timeout logic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
9 lines
407 B
JavaScript
9 lines
407 B
JavaScript
// Thin re-export — implementation lives in common/fetch-with-timeout.js
|
|
// so the front-end and back-end share one source of truth (just like
|
|
// valid-ip.js). Front-end callers keep writing:
|
|
//
|
|
// import { fetchWithTimeout } from '@/utils/fetch-with-timeout.js';
|
|
//
|
|
// Default timeout is 5s; pass { timeoutMs: ... } to override.
|
|
export { fetchWithTimeout } from '../../common/fetch-with-timeout.js';
|