Skip to main content

Cloud Hosting

init

1. Interface Description

Function: Initialize the Cloud Hosting code project.

Interface declaration: init(params: { serverName: string; template?: string; targetPath?: string }): Promise<{ projectDir: string }>

2. Input Parameters

FieldRequiredTypeDescription
serverNameYesStringService name, which will be used as the project directory name
templateNoStringTemplate identifier, defaults to 'helloworld'
targetPathNoStringTarget path, defaults to the current directory

3. Response

FieldTypeDescription
projectDirStringInitialized project directory

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
const { projectDir } = await manager.cloudrun.init({
serverName: "my-server",
template: "helloworld",
targetPath: "./projects",
});
console.log("Project has been initialized to:", projectDir);
}

test();

download

1. Interface Description

Function: Download the Cloud Hosting service code to the local directory.

Interface declaration: download(params: { serverName: string; targetPath: string }): Promise<void>

2. Input Parameters

FieldRequiredTypeDescription
serverNameYesStringService name to download
targetPathYesStringTarget path for download (absolute or relative path)

3. Response

No direct data is returned. The Promise resolves on success and rejects on failure.

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
await manager.cloudrun.download({
serverName: "my-server",
targetPath: "./downloads",
});
console.log("Code download completed");
}

test();

list

1. Interface Description

Function: Get the list of Cloud Hosting services

Interface declaration: list(params?: { pageSize?: number; pageNum?: number; serverName?: string; serverType?: CloudrunServerType }): Promise<ICloudrunListResponse>

2. Input Parameters

FieldRequiredTypeDescription
pageSizeNoNumberNumber of items per page, default 10
pageNumNoNumberPage number, default 1
serverNameNoStringService name filter
serverTypeNoCloudrunServerTypeService type filter (function/container)

3. Response

FieldTypeDescription
ServerListICloudrunServerBaseInfo[]Service list array
ServerList[].ServerNameStringService name
ServerList[].DefaultDomainNameStringDefault service domain
ServerList[].CustomDomainNameStringCustom domain name
ServerList[].StatusStringService status (running/deploying/deploy_failed)
ServerList[].UpdateTimeStringUpdate time
ServerList[].AccessTypesString[]Public network access types array
ServerList[].CustomDomainNamesString[]Custom domain names array
ServerList[].ServerTypeStringService type (function/container)
ServerList[].TrafficTypeStringTraffic type
TotalNumberTotal services
RequestIdStringRequest ID

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
const { ServerList, Total } = await manager.cloudrun.list({
pageSize: 20,
pageNum: 1,
});
console.log(`Total ${Total} services:`, ServerList);
}

test();

detail

1. Interface Description

Function: Query the details of the Cloud Hosting service

Interface declaration: detail(params: { serverName: string }): Promise<ICloudrunDetailResponse>

2. Input Parameters

FieldRequiredTypeDescription
serverNameYesStringService name to query

3. Response

FieldTypeDescription
BaseInfoICloudrunServerBaseInfoBasic service information
BaseInfo.ServerNameStringService name
BaseInfo.DefaultDomainNameStringDefault service domain
BaseInfo.CustomDomainNameStringCustom domain name
BaseInfo.StatusStringService status
BaseInfo.UpdateTimeStringUpdate time
BaseInfo.AccessTypesString[]Public network access types
BaseInfo.CustomDomainNamesString[]Custom domain names
BaseInfo.ServerTypeStringService type
BaseInfo.TrafficTypeStringTraffic type
ServerConfigICloudrunServerBaseConfigService configuration information
ServerConfig.EnvIdStringEnvironment ID
ServerConfig.ServerNameStringService name
ServerConfig.OpenAccessTypesString[]Public network access types
ServerConfig.CpuNumberCPU spec
ServerConfig.MemNumberMemory spec
ServerConfig.MinNumNumberMinimum replica count
ServerConfig.MaxNumNumberMaximum replica count
ServerConfig.PolicyDetailsICloudrunHpaPolicy[]Autoscaling configuration
ServerConfig.PolicyDetails[].PolicyTypeStringAutoscaling type. Valid values:
- "cpu": Autoscaling based on CPU utilization
- "mem": Autoscaling based on memory utilization
- "cpu/mem": Autoscaling based on both CPU and memory utilization
ServerConfig.PolicyDetails[].PolicyThresholdNumberAutoscaling threshold (percentage). Value range: 0-100. For example, 60 means autoscaling is triggered when resource utilization reaches 60%.
ServerConfig.CustomLogsStringLog collection path
ServerConfig.EnvParamsStringEnvironment variable
ServerConfig.InitialDelaySecondsNumberInitial delay
ServerConfig.CreateTimeStringCreation time
ServerConfig.PortNumberService port
ServerConfig.HasDockerfileBooleanWhether a Dockerfile exists
ServerConfig.DockerfileStringDockerfile name
ServerConfig.BuildDirStringBuild directory
ServerConfig.LogTypeStringLog type
ServerConfig.LogSetIdStringCLS logset ID
ServerConfig.LogTopicIdStringCLS topic ID
ServerConfig.LogParseTypeStringLog parsing type
ServerConfig.TagStringService tag
ServerConfig.InternalAccessStringIntranet access switch
ServerConfig.InternalDomainStringIntranet domain
ServerConfig.OperationModeStringOperation mode
ServerConfig.TimerScaleICloudrunTimerScale[]Scheduled autoscaling configuration
ServerConfig.TimerScale[].CycleTypeStringCycle type, optional values:
- "none": No cycle
- "daily": Daily cycle
- "weekly": Weekly cycle
- "monthly": Monthly cycle
ServerConfig.TimerScale[].StartDateStringCycle start date (Format: YYYY-MM-DD)
ServerConfig.TimerScale[].EndDateStringCycle end date (Format: YYYY-MM-DD)
ServerConfig.TimerScale[].StartTimeStringStart time (Format: HH:mm:ss)
ServerConfig.TimerScale[].EndTimeStringEnd time (Format: HH:mm:ss)
ServerConfig.TimerScale[].ReplicaNumNumberReplica count (min: 0)
ServerConfig.EntryPointString[]Dockerfile EntryPoint parameters
ServerConfig.CmdString[]Dockerfile Cmd arguments
OnlineVersionInfosICloudrunOnlineVersionInfo[]Online version information
OnlineVersionInfos[].VersionNameStringVersion name
OnlineVersionInfos[].ImageUrlStringImage URL
OnlineVersionInfos[].FlowRatioStringTraffic ratio
RequestIdStringRequest ID

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
const detail = await manager.cloudrun.detail({
serverName: "my-server",
});
console.log("Service details:", detail);
}

test();

delete

1. Interface Description

Function: Delete the specified cloud hosting service

Interface declaration: delete(params: { serverName: string }): Promise<IResponseInfo>

2. Input Parameters

FieldRequiredTypeDescription
serverNameYesStringService name to delete

3. Response

FieldTypeDescription
RequestIdStringRequest ID

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
await manager.cloudrun.delete({
serverName: "my-server",
});
console.log("Service deleted successfully");
}

test();

deploy

1. Interface Description

Function: Deploy local code to the cloud hosting service.

Interface declaration: deploy(params: { serverName: string; targetPath: string; serverConfig?: Partial<ICloudrunServerBaseConfig> }): Promise<IResponseInfo>

2. Input Parameters

FieldRequiredTypeDescription
serverNameYesStringService name to be deployed
targetPathYesStringLocal code path
serverConfigNoPartial<ICloudrunServerBaseConfig>Service configuration item, including the following optional fields:
- OpenAccessTypes: string[] - Public network access types. Optional values:
"OA" - Office network access
"PUBLIC" - Public network access
"MINIAPP" - Mini Program access
"VPC" - VPC access
- Cpu: number - CPU spec
- Mem: number - Memory spec
- MinNum: number - Minimum number of instances
- MaxNum: number - Maximum number of instances
- PolicyDetails: ICloudrunHpaPolicy[] - Array of autoscaling configurations. Each element contains:
PolicyType: string - Autoscaling type. Optional values: "cpu", "mem", "cpu/mem"
PolicyThreshold: number - Autoscaling threshold (percentage), e.g., 60 indicates 60%
- CustomLogs: string - Custom log configuration
- EnvParams: string - Environment variable JSON string
- Port: number - Service port (fixed to 3000 for function-type services)
- Dockerfile: string - Dockerfile name
- BuildDir: string - Build directory
- InternalAccess: string - Intranet access switch
- InternalDomain: string - Intranet domain
- EntryPoint: string[] - Dockerfile EntryPoint parameters
- Cmd: string[] - Dockerfile Cmd arguments

3. Response

FieldTypeDescription
RequestIdStringRequest ID

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
await manager.cloudrun.deploy({
serverName: "my-server",
targetPath: "./my-project",
serverConfig: {
Cpu: 0.5,
Mem: 1,
MinNum: 1,
MaxNum: 5,
},
});
console.log("Service deployed successfully");
}

test();

getTemplates

1. Interface Description

Function: Get the list of Cloud Hosting service templates

Interface declaration: getTemplates(): Promise<ITemplate[]>

2. Input Parameters

None

3. Response

FieldTypeDescription
ITemplate[]ArrayTemplate array
[].identifierStringTemplate unique identifier
[].titleStringTemplate title
[].descriptionStringTemplate description
[].runtimeVersionStringRuntime version
[].languageStringProgramming language
[].zipFileStoreStringTemplate zip file storage location

4. Sample Code

import CloudBase from "@cloudbase/manager-node";

const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});

async function test() {
const templates = await manager.cloudrun.getTemplates();
console.log("Available templates:", templates);
templates.forEach((template) => {
console.log(`Template ID: ${template.identifier}`);
console.log(`Title: ${template.title}`);
console.log(`Description: ${template.description}`);
console.log(`Runtime version: ${template.runtimeVersion}`);
console.log(`Language: ${template.language}`);
console.log(`Download URL: ${template.zipFileStore}`);
});
}

test();