Skip to content

Commit 991dc40

Browse files
committed
feat: update deployCdn supporting onlyRefresh
1 parent ecb3e44 commit 991dc40

File tree

6 files changed

+30
-91
lines changed

6 files changed

+30
-91
lines changed

doc/configure.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ inputs:
130130
| ---------- | -------- | ------- | --------------------------------------------------------------------------------- |
131131
| async | 否 | `false` | 是否为异步操作,如果为 true,则不会等待 CDN 创建或更新成功再返回, |
132132
| autoRefesh | 否 | `false` | 是否自动刷新预热 CDN |
133+
| onlyRefesh | 否 | `false` | 是否只刷新预热 CDN,如果为 `true`,那么只进行刷新预热操作,不会更新 CDN 配置 |
134+
| refreshCdn | 否 | | 刷新 CDN 相关配置,参考 [refreshCdn](#refreshCdn) |
133135
| host | 是 | | 需要接入的 CDN 域名。 |
134136
| host | 是 | | 需要接入的 CDN 域名。 |
135137
| https | 否 | | Https 加速配置,参考:https://cloud.tencent.com/document/api/228/30987#Https |
@@ -140,4 +142,10 @@ inputs:
140142

141143
> 注意:`async` 参数对于配置多个 CDN 域名需求,或者在 CI 流程中时,建议配置成 `true`,不然会导致 serverless cli 执行超时,或者 CI 流程超时。
142144

145+
#### refreshCdn
146+
147+
| 参数名称 | 是否必选 | 默认 | 描述 |
148+
| -------- | -------- | ---- | ------------------- |
149+
| urls | 否 | [] | 需要刷新的 CDN 路径 |
150+
143151
更多配置,请移至官方云 API 文档:https://cloud.tencent.com/document/product/228/41123

doc/serverless.yaml

Lines changed: 0 additions & 80 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@serverless/website",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"main": "./serverless.js",
55
"publishConfig": {
66
"access": "public"

serverless.component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: website
2-
version: 0.0.5
2+
version: 0.0.6
33
author: Tencent Cloud, Inc.
44
org: Tencent Cloud, Inc.
55
description: Deploys Tencent Website.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"fs-extra": "^8.1.0",
1616
"request": "^2.88.2",
1717
"string-random": "^0.1.3",
18-
"tencent-component-toolkit": "^1.5.4",
18+
"tencent-component-toolkit": "^1.7.2",
1919
"type": "^2.0.0"
2020
}
2121
}

src/serverless.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,23 @@ class ServerlessComponent extends Component {
7272
originPullProtocol: originPullProtocol
7373
}
7474

75-
if (cdnInputs.autoRefesh) {
75+
if (cdnInputs.autoRefresh) {
7676
cdnInputs.refreshCdn = {
7777
urls: [`http://${cdnInputs.domain}`, `https://${cdnInputs.domain}`]
7878
}
7979
}
8080
tencentCdnOutput = await cdn.deploy(cdnInputs)
8181
protocol = tencentCdnOutput.https ? 'https' : 'http'
82-
cdnResult.push(
83-
protocol + '://' + tencentCdnOutput.domain + ' (CNAME: ' + tencentCdnOutput.cname + ')'
84-
)
82+
const result = {
83+
domain: `${protocol}://${tencentCdnOutput.domain}`,
84+
cname: tencentCdnOutput.cname
85+
}
86+
if (cdnInputs.onlyRefresh !== true) {
87+
if (cdnInputs.refreshCdn && cdnInputs.refreshCdn.urls) {
88+
result.refreshUrls = cdnInputs.refreshCdn.urls
89+
}
90+
cdnResult.push(result)
91+
}
8592
outputs.push(tencentCdnOutput)
8693
}
8794
return {
@@ -158,7 +165,7 @@ class ServerlessComponent extends Component {
158165
originPullProtocol: websiteInputs.protocol
159166
})
160167

161-
output.hosts = deployCdnRes.cdnResult
168+
output.cdnDomains = deployCdnRes.cdnResult
162169
this.state.cdn = deployCdnRes.outputs
163170
}
164171

@@ -176,15 +183,19 @@ class ServerlessComponent extends Component {
176183

177184
// 默认值
178185
const { region } = this.state
186+
const stateCdn = this.state.cdn
179187

180188
// 创建cos对象
181189
const cos = new Cos(credentials, region)
182190
await cos.remove(this.state.website)
183191

184-
if (this.state.cdn) {
192+
if (stateCdn) {
185193
const cdn = new Cdn(credentials, region)
186-
for (let i = 0; i < this.state.cdn.length; i++) {
187-
await cdn.remove(this.state.cdn[i])
194+
for (let i = 0; i < stateCdn.length; i++) {
195+
const curCdnConf = stateCdn[i]
196+
if (curCdnConf.created === true) {
197+
await cdn.remove(curCdnConf)
198+
}
188199
}
189200
}
190201

0 commit comments

Comments
 (0)