From f1d1b58ed9d868d480643e9626e44c20e9265f0f Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Tue, 28 Apr 2026 13:46:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E5=BC=95=E5=85=A5=20undici=20Proxy?= =?UTF-8?q?Agent=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=9B=BD=E5=86=85=E7=9B=B4?= =?UTF-8?q?=E8=BF=9E=E5=B8=81=E5=AE=89=20API=20=E7=9A=84=20Timeout=20?= =?UTF-8?q?=E5=B0=81=E9=94=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 ++++++++++ package.json | 1 + src/actions/market.ts | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 29995b3..3b46b02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "recharts": "^3.8.1", "tailwind-merge": "^3.5.0", "tailwindcss-animate": "^1.0.7", + "undici": "^8.1.0", "zod": "^4.3.6" }, "devDependencies": { @@ -9215,6 +9216,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici": { + "version": "8.1.0", + "resolved": "https://registry.npmmirror.com/undici/-/undici-8.1.0.tgz", + "integrity": "sha512-E9MkTS4xXLnRPYqxH2e6Hr2/49e7WFDKczKcCaFH4VaZs2iNvHMqeIkyUAD9vM8kujy9TjVrRlQ5KkdEJxB2pw==", + "license": "MIT", + "engines": { + "node": ">=22.19.0" + } + }, "node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-6.21.0.tgz", diff --git a/package.json b/package.json index 8574403..545f474 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "recharts": "^3.8.1", "tailwind-merge": "^3.5.0", "tailwindcss-animate": "^1.0.7", + "undici": "^8.1.0", "zod": "^4.3.6" }, "devDependencies": { diff --git a/src/actions/market.ts b/src/actions/market.ts index 72000fd..a1b90bd 100644 --- a/src/actions/market.ts +++ b/src/actions/market.ts @@ -1,5 +1,6 @@ 'use server'; +import { ProxyAgent } from 'undici'; import { db } from '@/db'; import { assets } from '@/db/schema'; import { eq } from 'drizzle-orm'; @@ -22,6 +23,9 @@ export async function syncAllMarketPrices() { .select() .from(assets); + const proxyUrl = process.env.HTTPS_PROXY; + const proxyDispatcher = proxyUrl ? new ProxyAgent(proxyUrl) : undefined; + let successCount = 0; for (const asset of allAssets) { @@ -48,7 +52,7 @@ export async function syncAllMarketPrices() { } } else if (asset.type === 'CRYPTO') { const cryptoSymbol = asset.symbol.trim().toUpperCase() + 'USDT'; - const response = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=${cryptoSymbol}`, { cache: 'no-store' }); + const response = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=${cryptoSymbol}`, { cache: 'no-store', dispatcher: proxyDispatcher } as RequestInit & { dispatcher?: any }); if (response.ok) { const data = await response.json();