fix(api): 引入 undici ProxyAgent,解决国内直连币安 API 的 Timeout 封锁问题
This commit is contained in:
parent
48e834e338
commit
f1d1b58ed9
10
package-lock.json
generated
10
package-lock.json
generated
@ -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",
|
||||
|
||||
@ -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": {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user