May 20, 2021 WeChat Mini Program Development Document
Support side: Cloud function 1.1.0
Flags the current environment, noting that the value is not a string of the current environment ID and is equivalent to Symbol.for ('DYNAMIC_CURRENT_ENV') and is used to flag the current environment. If the constant value is passed to the env parameter in init, subsequent API requests will automatically request cloud resources for the current environment, such as cloud function A, which is currently in the environment of test-123, and then request the database, file store, and cloud function by default when requesting the environment test-123 database, file store, and cloud function.
Constants can be used to:
Note:
cloud.init: Set the API default environment equal to the current environment
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
cloud.database: The calling environment for setting up a new database object is equal to the current environment
cloud.init({
env: 'xxx'
})
// 不同于 init 时设置的环境,db 对象的请求将会去到和当前云函数所在环境相同的环境
const db = cloud.database({
env: cloud.DYNAMIC_CURRENT_ENV
})
cloud.callFunction: Set the called cloud function of the same environment
cloud.init({
env: 'xxx'
})
// 不同于 init 时设置的环境,对云函数 getInfo 的请求将会去到和当前云函数所在环境相同的环境
const callResult = await cloud.callFunction({
name: 'getInfo',
config: {
env: cloud.DYNAMIC_CURRENT_ENV
},
data: {
// ...
},
})