Skip to content

Commit 5975396

Browse files
committed
feat: support disable creating apigw
1 parent bc59958 commit 5975396

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/serverless.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { MultiApigw, Scf, Apigw, Cos, Cns } = require('tencent-component-toolkit'
33
const { packageCode, getDefaultProtocol, deleteRecord, prepareInputs } = require('./utils')
44
const CONFIGS = require('./config')
55

6-
class Express extends Component {
6+
class ServerlessComponent extends Component {
77
getCredentials() {
88
const { tmpSecrets } = this.credentials.tencent
99

@@ -101,6 +101,9 @@ class Express extends Component {
101101
}
102102

103103
async deployApigateway(credentials, inputs, regionList) {
104+
if (inputs.isDisabled) {
105+
return {}
106+
}
104107
const apigw = new MultiApigw(credentials, regionList)
105108
inputs.oldState = {
106109
apiList: (this.state[regionList[0]] && this.state[regionList[0]].apiList) || []
@@ -192,10 +195,15 @@ class Express extends Component {
192195
if (!functionConf.code.src) {
193196
outputs.templateUrl = CONFIGS.templateUrl
194197
}
195-
const [apigwOutputs, functionOutputs] = await Promise.all([
196-
this.deployApigateway(credentials, apigatewayConf, regionList, outputs),
197-
this.deployFunction(credentials, functionConf, regionList, outputs)
198-
])
198+
199+
const deployTasks = [this.deployFunction(credentials, functionConf, regionList, outputs)]
200+
// support apigatewayConf.isDisabled
201+
if (apigatewayConf.isDisabled !== true) {
202+
deployTasks.push(this.deployApigateway(credentials, apigatewayConf, regionList, outputs))
203+
} else {
204+
this.state.apigwDisabled = true
205+
}
206+
const [functionOutputs, apigwOutputs = {}] = await Promise.all(deployTasks)
199207

200208
// optimize outputs for one region
201209
if (regionList.length === 1) {
@@ -208,8 +216,8 @@ class Express extends Component {
208216
outputs['scf'] = functionOutputs
209217
}
210218

211-
// 云解析遇到等API网关部署完成才可以继续部署
212-
if (cnsConf.length > 0) {
219+
// cns depends on apigw, so if disabled apigw, just ignore it.
220+
if (cnsConf.length > 0 && apigatewayConf.isDisabled !== true) {
213221
outputs['cns'] = await this.deployCns(credentials, cnsConf, regionList, apigwOutputs)
214222
}
215223

@@ -239,13 +247,16 @@ class Express extends Component {
239247
functionName: curState.functionName,
240248
namespace: curState.namespace
241249
})
242-
await apigw.remove({
243-
created: curState.created,
244-
environment: curState.environment,
245-
serviceId: curState.serviceId,
246-
apiList: curState.apiList,
247-
customDomains: curState.customDomains
248-
})
250+
// if disable apigw, no need to remove
251+
if (state.apigwDisabled !== true) {
252+
await apigw.remove({
253+
created: curState.created,
254+
environment: curState.environment,
255+
serviceId: curState.serviceId,
256+
apiList: curState.apiList,
257+
customDomains: curState.customDomains
258+
})
259+
}
249260
}
250261
removeHandlers.push(handler())
251262
}
@@ -263,4 +274,4 @@ class Express extends Component {
263274
}
264275
}
265276

266-
module.exports = Express
277+
module.exports = ServerlessComponent

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
210210

211211
// 对apigw inputs进行标准化
212212
const apigatewayConf = inputs.apigatewayConf ? inputs.apigatewayConf : {}
213+
apigatewayConf.isDisabled = inputs.apigatewayConf === true
213214
apigatewayConf.fromClientRemark = fromClientRemark
214215
apigatewayConf.serviceName = inputs.serviceName
215216
apigatewayConf.description = `Serverless Framework Tencent-${capitalString(

0 commit comments

Comments
 (0)