Skip to main content

Custom Domain

Manage the custom domain binding and HTTP access routing rules for TCB environments. Access via app.env.

version tip

Since v5.0.0, this capability has been added. Before v5.0.0, please use HTTP Gateway (Legacy).

Conceptual Overview

ConceptDescription
Custom DomainCustom domain bound to TCB HTTP Gateway, supports HTTPS certificate configuration
Access RoutingConfigure path-to-upstream service (SCF/Cloud Run/Static Hosting) mapping rules under a domain
AccessTypeDomain access method: DIRECT (Direct) / CDN (TCB CDN) / CUSTOM (Custom CDN/WAF)
ProtocolHTTPS protocol policy: HTTP_AND_HTTPS / HTTP_TO_HTTPS (force redirect) / HTTPS_TO_HTTP
UpstreamResourceTypeRouting upstream type: SCF (Cloud Function) / CBR (Cloud Run) / STATIC_STORE (Static Hosting) / WEB_SCF (Web Cloud Function)

describeHttpServiceRoute

1. API Description

API feature: queries the list of domains and access routes in the environment, supports multi-dimensional filtering

API declaration: app.env.describeHttpServiceRoute(params): Promise<DescribeHttpServiceRouteRes>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
EnvIdYesStringEnvironment ID
FiltersOptionalHTTPServiceRouteFilter[]Filter conditions, supporting Domain, Path, DomainType, UpstreamResourceType
OffsetNoNumberPagination offset, default 0
LimitNoNumberPage size, default 20, maximum 1000

3. Return Results

FieldTypeDescription
DomainsHTTPServiceDomain[]List of domain routing information
OriginDomainStringHTTP service origin domain (for custom CDN/WAF origin)
TotalCountNumberTotal number of domains
RequestIdStringUnique identifier of the request

HTTPServiceDomain

FieldTypeDescription
DomainStringDomain
DomainTypeStringDomain type
AccessTypeStringAccess method: DIRECT / CDN / CUSTOM
CertIdStringSSL Certificate ID
ProtocolStringProtocol type
CnameStringTarget value of the CNAME to be configured
IsDefaultBooleanWhether it is the default domain
EnableBooleanWhether it has been enabled
StatusStringStatus: PROCESSING / FAIL / SUCCESS
DNSStatusStringDNS resolution status: OK / INVALID
RoutesHTTPServiceRoute[]List of routes under the domain
CreateTimeStringCreation time
UpdateTimeStringUpdate time

4. Sample Code

const CloudBase = require('@cloudbase/manager-node')
const app = new CloudBase({ secretId: 'Your SecretId', secretKey: 'Your SecretKey', envId: 'your-env-id' })

async function test() {
const { Domains, TotalCount } = await app.env.describeHttpServiceRoute({
EnvId: 'your-env-id',
Limit: 20
})
console.log(`Total ${TotalCount} domains`)
Domains.forEach(d => console.log(d.Domain, d.Status, d.DNSStatus))
}

test()

bindCustomDomain

1. API Description

API feature: Bind custom domains to HTTP Gateway, supports configuring HTTPS certificates and access methods.

API declaration: app.env.bindCustomDomain(params): Promise<BindCustomDomainRes>

Call recommendation

It is recommended to call verifyHttpServiceRoute first to run ownership/conflict prechecks, and bind the domain only after precheck passes.

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
EnvIdYesStringEnvironment ID
DomainYesBindCustomDomainDomainParamDomain configuration, see description below

BindCustomDomainDomainParam

FieldRequiredTypeDescription
DomainRequiredStringDomain, globally unique
CertIdYesStringSSL Certificate ID (Tencent Cloud SSL Platform)
AccessTypeNoStringAccess method: DIRECT (default) / CDN / CUSTOM
ProtocolNoStringProtocol policy: default HTTP_AND_HTTPS
EnableNoBooleanWhether to enable immediately, default true
CustomCnameNoStringCustom CDN/WAF origin CNAME (required when AccessType=CUSTOM)

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request

4. Sample Code

async function test() {
await app.env.bindCustomDomain({
EnvId: 'your-env-id',
Domain: {
Domain: 'api.example.com',
CertId: 'your-cert-id',
AccessType: 'DIRECT',
Protocol: 'HTTP_TO_HTTPS'
}
})
console.log('Domain name binding succeeded. Please configure the CNAME record with your DNS provider.')
}

test()

deleteCustomDomain

1. API Description

API feature: Delete custom domains. An error will be thrown if routes are bound to the domain. Delete the routes first.

API declaration: app.env.deleteCustomDomain(params): Promise<DeleteCustomDomainRes>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
EnvIdYesStringEnvironment ID
DomainRequiredStringDomain name to be deleted

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request

verifyHttpServiceRoute

1. API Description

API feature: performs read-only prechecks for domain/route configurations before create/modify. It does not create or modify any resources.

API declaration: app.env.verifyHttpServiceRoute(params): Promise<VerifyHttpServiceRouteRes>

version tip

This API has been supported since v5.8.0.

2. Input Parameters

FieldRequiredTypeDescription
EnvIdYesStringEnvironment ID
DomainYesHTTPServiceDomainParamDomain and route configuration. See details below.

HTTPServiceDomainParam

FieldRequiredTypeDescription
DomainYesStringDomain (globally unique)
AccessTypeNoStringBinding type: DIRECT / CDN / CUSTOM / EO
CertIdNoStringSSL platform certificate ID under the current account
ProtocolNoStringProtocol policy: HTTP / HTTPS / HTTP_AND_HTTPS / HTTP_TO_HTTPS / HTTPS_TO_HTTP
CustomCnameNoStringCustom CNAME, used only when AccessType=CUSTOM
EnableNoBooleanDomain enabled status; enabled by default when omitted
RoutesNoHTTPServiceRouteParam[]Route list, up to 20 items
ExtensionNoHTTPServiceExtensionDomain extension configuration

HTTPServiceRouteParam (single route)

FieldRequiredTypeDescription
PathYesStringRoute path, e.g. /api
UpstreamResourceTypeNoStringUpstream type: SCF / CBR / STATIC_STORE / WEB_SCF / LH / STORAGE (required for create, optional for modify)
UpstreamResourceNameNoStringUpstream service name (required for create, optional for modify; can be omitted for STATIC_STORE / STORAGE)
PathRewriteNoHTTPServicePathRewritePath rewrite configuration
EnableSafeDomainNoBooleanWhether to enable safe domain, default true
EnableAuthNoBooleanWhether to enable identity authentication, default false
EnablePathTransmissionNoBooleanWhether to enable path transmission, default false
QPSPolicyNoHTTPServiceRouteQPSPolicyQPS rate limiting policy
ExtensionNoHTTPServiceExtensionRoute extension configuration (including headers handling)
EnableNoBooleanWhether to enable route

HTTPServicePathRewrite

FieldRequiredTypeDescription
PrefixNoStringPath prefix rewrite. Mutually exclusive with StaticStorePrefix.
StaticStorePrefixNoStringStatic hosting path prefix rewrite. Mutually exclusive with Prefix.

HTTPServiceRouteQPSPolicy

FieldRequiredTypeDescription
QPSTotalNoNumberGlobal QPS value (requests per second).
QPSPerClientNoHTTPServiceQPSPerClientPer-client rate limiting configuration.

HTTPServiceQPSPerClient

FieldRequiredTypeDescription
LimitByNoStringClient dimension: UserID / ClientIP.
LimitValueNoNumberPer-client QPS limit value (requests per second).

HTTPServiceExtension

FieldRequiredTypeDescription
HeadersHandlerNoHTTPServiceHeadersHandlerHeaders handling configuration.

HTTPServiceHeadersHandler

FieldRequiredTypeDescription
RequestHeadersToAddNoHTTPServiceHeaderToAdd[]List of request headers to add.
RequestHeadersToRemoveNoString[]List of request header keys to remove.
ResponseHeadersToAddNoHTTPServiceHeaderToAdd[]List of response headers to add.
ResponseHeadersToRemoveNoString[]List of response header keys to remove.

HTTPServiceHeaderToAdd

FieldRequiredTypeDescription
KeyNoStringHeader key to add.
ValueNoStringHeader value to add.
ActionNoStringAdd behavior: APPEND_IF_EXISTS_OR_ADD / ADD_IF_ABSENT / OVERWRITE_IF_EXISTS_OR_ADD / OVERWRITE_IF_EXISTS.

3. Return Results

FieldTypeDescription
PassedBooleantrue when all enabled checks pass
OwnershipVerifyHttpServiceRouteCheckItemDomain ownership check result
CertVerifyHttpServiceRouteCheckItemCertificate check result
QuotaVerifyHttpServiceRouteCheckItemDomain/path quota check result
RouteConflictVerifyHttpServiceRouteCheckItemRoute conflict check result under the same domain
DomainConflictVerifyHttpServiceRouteCheckItemDomain occupancy conflict check result
InternalAccountVerifyHttpServiceRouteCheckItemInternal-domain/account check result
BlacklistVerifyHttpServiceRouteCheckItemDomain blacklist check result
CDNResourceVerifyHttpServiceRouteCheckItemCDN resource check result
EOVerifyHttpServiceRouteCheckItemEdgeOne precheck result
RequestIdStringUnique identifier of the request

VerifyHttpServiceRouteCheckItem structure:

FieldTypeDescription
StatusStringCheck status: PASS / SKIPPED / FAIL
CodeStringFailure code, returned only when FAIL
MessageStringDetail message or skip reason
OwnershipVerificationObjectOwnership verification guidance (e.g. DNS record/file verification info)

4. Sample Code

It is recommended to call verifyHttpServiceRoute before creating or updating routes. If Passed=true, proceed with domain binding and route creation.

async function test() {
const verifyRes = await app.env.verifyHttpServiceRoute({
EnvId: 'your-env-id',
Domain: {
Domain: 'api.example.com',
CertId: 'your-cert-id'
}
})

if (!verifyRes.Passed) {
console.log('Precheck failed. Complete ownership verification or resolve conflicts, then retry.')
console.log(verifyRes.Ownership, verifyRes.RouteConflict, verifyRes.DomainConflict)
return
}

console.log('Precheck passed. You can continue with bindCustomDomain / createHttpServiceRoute.')
}

test()

createHttpServiceRoute

1. API Description

API feature: Create access routing under a specified domain, mapping paths to upstream services such as SCF, Cloud Run, or Static Hosting.

API declaration: app.env.createHttpServiceRoute(params): Promise<CreateHttpServiceRouteRes>

Call recommendation

It is recommended to call verifyHttpServiceRoute first and create routes only after Passed=true.

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
EnvIdYesStringEnvironment ID
DomainYesHTTPServiceDomainParamDomain and routing configuration, see description below

HTTPServiceDomainParam

FieldRequiredTypeDescription
DomainYesStringDomain (globally unique)
AccessTypeNoStringBinding type: DIRECT / CDN / CUSTOM / EO
CertIdNoStringSSL platform certificate ID under the current account
ProtocolNoStringProtocol policy: HTTP / HTTPS / HTTP_AND_HTTPS / HTTP_TO_HTTPS / HTTPS_TO_HTTP
CustomCnameNoStringCustom CNAME, used only when AccessType=CUSTOM
EnableNoBooleanDomain enabled status; enabled by default when omitted
RoutesNoHTTPServiceRouteParam[]Route list, up to 20 items
ExtensionNoHTTPServiceExtensionDomain extension configuration

HTTPServiceRouteParam (single route)

FieldRequiredTypeDescription
PathYesStringRoute path, e.g. /api
UpstreamResourceTypeNoStringUpstream type: SCF / CBR / STATIC_STORE / WEB_SCF / LH / STORAGE (required for create, optional for modify)
UpstreamResourceNameNoStringUpstream service name (required for create, optional for modify; can be omitted for STATIC_STORE / STORAGE)
PathRewriteNoHTTPServicePathRewritePath rewrite configuration
EnableSafeDomainNoBooleanWhether to enable safe domain, default true
EnableAuthNoBooleanWhether to enable identity authentication, default false
EnablePathTransmissionNoBooleanWhether to enable path transmission, default false
QPSPolicyNoHTTPServiceRouteQPSPolicyQPS rate limiting policy
ExtensionNoHTTPServiceExtensionRoute extension configuration (including headers handling)
EnableNoBooleanWhether to enable route

The semantics of PathRewrite / EnableAuth / EnablePathTransmission / QPSPolicy align with the CLI gateway configuration. See Configuration File - Gateway for the authoritative definitions. The Manager SDK uses PascalCase (e.g. EnableAuth), corresponding one-to-one with the camelCase (enableAuth) in cloudbaserc.json.

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request

4. Sample Code

async function test() {
// Create a route under the bound domain: map /api to the SCF my-function
await app.env.createHttpServiceRoute({
EnvId: 'your-env-id',
Domain: {
Domain: 'api.example.com',
Routes: [
{
Path: '/api',
UpstreamResourceType: 'SCF',
UpstreamResourceName: 'my-function',
EnableAuth: false,
Enable: true
}
]
}
})
console.log('Route created successfully')
}

test()

modifyHttpServiceRoute

1. API Description

API feature: Modify the access routing configuration under the specified domain.

API declaration: app.env.modifyHttpServiceRoute(params): Promise<ModifyHttpServiceRouteRes>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

Same as createHttpServiceRoute, see the description above.

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request

deleteHttpServiceRoute

1. API Description

API feature: Delete access routes under the specified domain. If Paths is not provided, delete all routes under the domain.

API declaration: app.env.deleteHttpServiceRoute(params): Promise<DeleteHttpServiceRouteRes>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
EnvIdYesStringEnvironment ID
DomainYesStringDomain
PathsNoString[]List of route paths to delete; if not passed, delete all routes under the domain

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request

4. Sample Code

async function test() {
// Delete the /api route
await app.env.deleteHttpServiceRoute({
EnvId: 'your-env-id',
Domain: 'api.example.com',
Paths: ['/api']
})

// Delete all routes under the domain
await app.env.deleteHttpServiceRoute({
EnvId: 'your-env-id',
Domain: 'api.example.com'
})
}

test()