fix(api): 引入 undici ProxyAgent,解决国内直连币安 API 的 Timeout 封锁问题

This commit is contained in:
2026-04-28 13:46:14 +08:00
parent 48e834e338
commit f1d1b58ed9
3 changed files with 16 additions and 1 deletions
+5 -1
View File
@@ -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();