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();