From 58db0b82eed03ff86584c6a7975b2ba98ae55b98 Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Tue, 28 Apr 2026 14:04:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E6=94=B9=E7=94=A8=20setGlobalDispa?= =?UTF-8?q?tcher=20=E6=96=B9=E6=A1=88=EF=BC=8C=E8=A7=A3=E5=86=B3=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E5=8F=82=E6=95=B0=E4=B8=8D=E5=85=BC=E5=AE=B9=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/market.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/actions/market.ts b/src/actions/market.ts index a1b90bd..faaad72 100644 --- a/src/actions/market.ts +++ b/src/actions/market.ts @@ -1,6 +1,6 @@ 'use server'; -import { ProxyAgent } from 'undici'; +import { ProxyAgent, setGlobalDispatcher } from 'undici'; import { db } from '@/db'; import { assets } from '@/db/schema'; import { eq } from 'drizzle-orm'; @@ -24,7 +24,10 @@ export async function syncAllMarketPrices() { .from(assets); const proxyUrl = process.env.HTTPS_PROXY; - const proxyDispatcher = proxyUrl ? new ProxyAgent(proxyUrl) : undefined; + if (proxyUrl) { + const proxyAgent = new ProxyAgent(proxyUrl); + setGlobalDispatcher(proxyAgent); + } let successCount = 0; @@ -52,7 +55,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', dispatcher: proxyDispatcher } as RequestInit & { dispatcher?: any }); + const response = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=${cryptoSymbol}`, { cache: 'no-store' }); if (response.ok) { const data = await response.json();