You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.7 KiB

应用初始化

参数

字段 类型 必填 说明
secretId string 腾讯云 API 固定密钥对,在云函数内执行可不填。前往获取
secretKey string 同上
env string TCB 环境 ID不填使用默认环境
proxy string 调用接口时使用的 http 代理 url
timeout number 调用接口的超时时间ms默认为 5000即 5 秒
credentials object Cloudbase 私钥,包含 private_keyprivate_key_id 两个字符串,可以通过云开发控制台获取
version string 版本号,依赖项目的版本号
// 初始化示例
const tcb = require('tcb-admin-node');

// 初始化资源
// 云函数下不需要secretId和secretKey。
// env如果不指定将使用默认环境
tcb.init({
  secretId: 'xxxxx',
  secretKey: 'xxxx',
  env: 'xxx'
});

//云函数下使用默认环境
tcb.init()

//云函数下指定环境
tcb.init({
  env: 'xxx'
})

//获取执行当前云函数的环境
tcb.getCurrentEnv()


//云函数下指定环境为当前的执行环境
tcb.init({
  env: tcb.getCurrentEnv()
})

//修改请求超时时间
tcb.init({
  timeout: 5000
})

//使用多个环境
//初始化环境'xx'和'zz'
const app = tcb.init({
  env: 'xx'
})

const app2 = tcb.init({
  env: 'zz'
})

解析云函数环境下的环境变量 context 取自云函数入口参数

const envObj = tcb.parseContext(context) // context 参数 取自云函数入口函数handler的context对象
console.log(envObj)