跳到主要内容

tcb routes edit

增量更新已有路由:用「域名 + 路径」定位路由,只更新传入的字段,未传入的保持不变。

v3.0.0+

tcb routes 自 v3.0.0 起提供。

语法​

tcb routes edit --data '<JSON>' [options]

参数​

参数必填说明默认值
--data <json>是路由配置 JSON,path 为定位键—
-e, --env-id <envId>否环境 ID配置文件 envId

JSON 结构与创建路由一致,domain 与 routes[].path 必填,其余字段按需传入。

示例​

# 更换上游服务
tcb routes edit -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/api","upstreamResourceName":"new-service"}]}'

# 禁用路由
tcb routes edit -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/api","enable":false}]}'

# 开启身份认证和路径透传
tcb routes edit -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/api","enableAuth":true,"enablePathTransmission":true}]}'

# 更新 QPS 限流
tcb routes edit -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/v1","qpsPolicy":{"qpsTotal":200,"qpsPerClient":{"limitBy":"ClientIP","limitValue":20}}}]}'

# 切换路由绑定的函数版本
tcb routes edit -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/func","upstreamResourceVersion":"3"}]}'

# 清除版本绑定,恢复资源侧流量控制
tcb routes edit -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/func","upstreamResourceVersion":"$DEFAULT"}]}'

注意事项​

  • 修改是增量更新,只更新传入的字段
  • upstreamResourceVersion 缺省时保留现有绑定;传 $DEFAULT 才清除绑定,语义见转发版本