tcb routes add
Create one or more routes for a domain, forwarding requests by "domain + path" to functions, CloudBase Run services, or static hosting.
v3.0.0+
tcb routes has been available since v3.0.0.
Usage
tcb routes add --data '<JSON>' [options]
Parameters
| Parameter | Required | Description | Default |
|---|---|---|---|
--data <json> | Yes | Route configuration JSON | — |
-e, --env-id <envId> | No | Environment ID | envId in the configuration |
Configuration format
{
"domain": "api.example.com",
"routes": [
{
"path": "/api",
"upstreamResourceType": "CBR",
"upstreamResourceName": "my-service",
"upstreamResourceVersion": "optional, functions only",
"enable": true,
"enableAuth": false,
"enableSafeDomain": true,
"enablePathTransmission": false,
"pathRewrite": { "prefix": "/newpath" },
"qpsPolicy": {
"qpsTotal": 500,
"qpsPerClient": { "limitBy": "ClientIP", "limitValue": 20 }
}
}
]
}
| Field | Type | Required | Description |
|---|---|---|---|
domain | string | Yes | Target domain, already bound with tcb domains add |
routes[].path | string | Yes | Path starting with /, no wildcards. Each segment allows letters, digits, ., _, - and at most 50 characters; reserved prefixes /__auth and /.well-known are rejected |
routes[].upstreamResourceType | string | Yes | SCF (function), CBR (CloudBase Run), STATIC_STORE (static hosting), WEB_SCF (web function), LH (lightweight server) |
routes[].upstreamResourceName | string | Yes | Upstream service name |
routes[].upstreamResourceVersion | string | No | Upstream version, SCF / WEB_SCF only; see Forwarding version. Defaults to $DEFAULT when omitted (v3.8.10+) |
routes[].enable | boolean | No | Whether the route is enabled, default true |
routes[].enableSafeDomain | boolean | No | Whether to enforce the security domain check, default true |
Authoritative definitions of enableAuth / enablePathTransmission / pathRewrite / qpsPolicy are in Configuration file - gateway. Differences between the imperative and declarative forms:
pathRewrite: the imperative form supportsprefixonly; the declarative form also supportsstaticStorePrefixqpsPolicy:qpsTotalis capped at 500 here and 100–100000 declaratively;qpsPerClient.limitValueis capped at 30 declarativelyenableAuth/enablePathTransmission: identical semantics
Examples
# Forward to a CloudBase Run service
tcb routes add -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/api","upstreamResourceType":"CBR","upstreamResourceName":"my-service"}]}'
# Forward to a function with authentication
tcb routes add -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/func","upstreamResourceType":"SCF","upstreamResourceName":"my-function","enableAuth":true}]}'
# Static site root
tcb routes add -e <envId> --data '{"domain":"www.example.com","routes":[{"path":"/","upstreamResourceType":"STATIC_STORE","upstreamResourceName":"website"}]}'
# With QPS limits
tcb routes add -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/v1","upstreamResourceType":"CBR","upstreamResourceName":"backend","qpsPolicy":{"qpsTotal":1000,"qpsPerClient":{"limitBy":"ClientIP","limitValue":50}}}]}'
# Several routes in one call
tcb routes add -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/v1","upstreamResourceType":"SCF","upstreamResourceName":"func-v1"},{"path":"/v2","upstreamResourceType":"CBR","upstreamResourceName":"service-v2"}]}'
# Forward to a specific function version
tcb routes add -e <envId> --data '{"domain":"api.example.com","routes":[{"path":"/func-v2","upstreamResourceType":"SCF","upstreamResourceName":"my-function","upstreamResourceVersion":"2"}]}'
Notes
pathrejects wildcards (/api/*,/*); to cover subpaths, declare several exact routes such as/apiand/api/v1STATIC_STOREsupports one path level only (/or/static), nested paths fail- Duplicate paths under one domain fail with
INVALID_PARAM; change an existing route withtcb routes edit - The imperative form requires the domain to be bound first via
tcb domains add; declarativetcb deploybinds it automatically