[ PROMPT_NODE_23982 ]
Argo Smart Routing 设计模式
[ SKILL_DOCUMENTATION ]
# 集成模式
## 启用 Argo + 分层缓存 (Tiered Cache)
typescript
async function enableOptimalPerformance(client: Cloudflare, zoneId: string) {
await Promise.all([
client.argo.smartRouting.edit({ zone_id: zoneId, value: 'on' }),
client.argo.tieredCaching.edit({ zone_id: zoneId, value: 'on' }),
]);
}
**流程:** 访客 → 边缘节点 (低层) → [缓存未命中] → 上层节点 → [缓存未命中 + Argo] → 源站
**影响:** Argo 可降低约 30% 的延迟 + 分层缓存可卸载 50-80% 的源站流量
## 使用分析 (GraphQL)
graphql
query ArgoAnalytics($zoneTag: string!) {
viewer {
zones(filter: { zoneTag: $zoneTag }) {
httpRequestsAdaptiveGroups(limit: 1000) {
sum { argoBytes, bytes }
}
}
}
}
**计费:** 约 $0.10/GB。DDoS 缓解和 WAF 拦截的流量不收费。
## Spectrum TCP 集成
为非 HTTP 流量(数据库、游戏服务器、IoT)启用 Argo:
typescript
// 更新现有应用
await client.spectrum.apps.update(appId, { zone_id: zoneId, argo_smart_routing: true });
// 创建带有 Argo 的新应用
await client.spectrum.apps.create({
zone_id: zoneId,
dns: { type: 'CNAME', name: 'tcp.example.com' },
origin_direct: ['tcp://origin.example.com:3306'],
protocol: 'tcp/3306',
argo_smart_routing: true,
});
**用例:** MySQL/PostgreSQL (3306/5432)、游戏服务器、MQTT (1883)、SSH (22)
## 预检验证
typescript
async function validateArgoEligibility(client: Cloudflare, zoneId: string) {
const status = await client.argo.smartRouting.get({ zone_id: zoneId });
const zone = await client.zones.get({ zone_id: zoneId });
const issues: string[] = [];
if (!status.editable) issues.push('域名不可编辑');
if (['free', 'pro'].includes(zone.plan.legacy_id)) issues.push('需要 Business+ 计划');
if (zone.status !== 'active') issues.push('域名未激活');
return { canEnable: issues.length === 0, issues };
}
## 启用后验证
typescript
async function verifyArgoEnabled(client: Cloudflare, zoneId: string): Promise {
await new Promise(r => setTimeout(r, 2000)); // 等待传播
const status = await client.argo.smartRouting.get({ zone_id: zoneId });
return status.value === 'on';
}
## 完整设置模式
typescript
async function setupArgo(client: Cloudflare, zoneId: string) {
// 1. 验证
const { canEnable, issues } = await validateArgoEligibility(client, zoneId);
if (!canEnable) throw new Error(issues.join(', '));