diff --git a/docs/configure.md b/docs/configure.md index efbe2c1..8e901e0 100644 --- a/docs/configure.md +++ b/docs/configure.md @@ -170,7 +170,7 @@ inputs: | eip | 否 | false | 固定出口 IP。默认为 false,即不启用 | | tags | 否 | | 标签设置。可设置多对 key-value 的键值对 | | events | 否 | | 触发器数组。支持以下几种触发器:timer(定时触发器)、apigw(网关触发器)、cos(COS 触发器)、cmq(CMQ Topic 触发器)、ckafka(CKafka 触发器)配置参数参考触发器。 | -| traffic | 否 | 1 | 配置默认流量中 `$LATEST` 版本比重,取值范围:0 ~ 1,比如 80%,可配置成 0.8。注意如果皮遏制灰度流量,需要配置对应的 API 网关触发器的 endpoints 的 `function.functionQualifier` 参数为 `$DEFAULT` (默认流量) | +| traffic | 否 | 1 | 配置默认流量中 `$LATEST` 版本比重,取值范围:0 ~ 1,比如 80%,可配置成 0.8。注意如果配置灰度流量,需要配置对应的 API 网关触发器的 endpoints 的 `function.functionQualifier` 参数为 `$DEFAULT` (默认流量) | ### 执行目录 diff --git a/src/package.json b/src/package.json index 877bd5d..f4531f0 100644 --- a/src/package.json +++ b/src/package.json @@ -9,7 +9,7 @@ "license": "Apache", "dependencies": { "download": "^8.0.0", - "tencent-component-toolkit": "^1.12.3", + "tencent-component-toolkit": "^1.12.4", "type": "^2.0.0" } } diff --git a/src/serverless.js b/src/serverless.js index 526025b..5b186d9 100644 --- a/src/serverless.js +++ b/src/serverless.js @@ -63,15 +63,25 @@ class ServerlessComponent extends Component { memorySize: scfOutput.MemorySize } - if (scfOutput.LastVersion) { - outputs.lastVersion = scfOutput.LastVersion - this.state.lastVersion = scfOutput.LastVersion + // default version is $LATEST + outputs.lastVersion = scfOutput.LastVersion + ? scfOutput.LastVersion + : this.state.lastVersion || '$LATEST' + + // default traffic is 1.0, it can also be 0, so we should compare to undefined + outputs.traffic = scfOutput.Traffic + ? scfOutput.Traffic + : this.state.traffic !== undefined + ? this.state.traffic + : 1 + + if (outputs.traffic !== 1 && scfOutput.ConfigTrafficVersion) { + outputs.configTrafficVersion = scfOutput.ConfigTrafficVersion + this.state.configTrafficVersion = scfOutput.ConfigTrafficVersion } - if (scfOutput.Traffic) { - outputs.traffic = scfOutput.Traffic - this.state.functionTraffic = scfOutput.Traffic - } + this.state.lastVersion = outputs.lastVersion + this.state.traffic = outputs.traffic // handle apigw event outputs if (existApigwTrigger) {