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 Access Service (Legacy).

Conceptual Overview

ConceptDescription
Custom DomainCustom domain bound to TCB HTTP access service, 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 access service, supports configuring HTTPS certificates and access methods.

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

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

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>

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 (already bound)
RoutesNoHTTPServiceRouteParam[]List of routes, up to 20 items
AccessTypeNoStringAccess method
CertIdNoStringSSL Certificate ID
ProtocolNoStringProtocol policy
EnableNoBooleanDomain enabled status

HTTPServiceRouteParam (single route)

FieldRequiredTypeDescription
PathYesStringRoute path, e.g. /api
UpstreamResourceTypeNoStringUpstream type: SCF / CBR / STATIC_STORE / WEB_SCF / LH
UpstreamResourceNameNoStringUpstream service name (e.g. SCF function name / Cloud Run service name)
PathRewriteNoHTTPServicePathRewritePath rewrite configuration
EnableSafeDomainNoBooleanWhether to enable the safe domain, default true
EnableAuthNoBooleanWhether to enable Identity Authentication, default false
EnablePathTransmissionNoBooleanWhether to enable path transmission, default false
QPSPolicyNoHTTPServiceRouteQPSPolicyQPS rate limiting policy
EnableNoBooleanWhether to enable route, default true

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()