@@ -3,7 +3,7 @@ const { MultiApigw, Scf, Apigw, Cos, Cns } = require('tencent-component-toolkit'
3
3
const { packageCode, getDefaultProtocol, deleteRecord, prepareInputs } = require ( './utils' )
4
4
const CONFIGS = require ( './config' )
5
5
6
- class Express extends Component {
6
+ class ServerlessComponent extends Component {
7
7
getCredentials ( ) {
8
8
const { tmpSecrets } = this . credentials . tencent
9
9
@@ -101,6 +101,9 @@ class Express extends Component {
101
101
}
102
102
103
103
async deployApigateway ( credentials , inputs , regionList ) {
104
+ if ( inputs . isDisabled ) {
105
+ return { }
106
+ }
104
107
const apigw = new MultiApigw ( credentials , regionList )
105
108
inputs . oldState = {
106
109
apiList : ( this . state [ regionList [ 0 ] ] && this . state [ regionList [ 0 ] ] . apiList ) || [ ]
@@ -192,10 +195,15 @@ class Express extends Component {
192
195
if ( ! functionConf . code . src ) {
193
196
outputs . templateUrl = CONFIGS . templateUrl
194
197
}
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 )
199
207
200
208
// optimize outputs for one region
201
209
if ( regionList . length === 1 ) {
@@ -208,8 +216,8 @@ class Express extends Component {
208
216
outputs [ 'scf' ] = functionOutputs
209
217
}
210
218
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 ) {
213
221
outputs [ 'cns' ] = await this . deployCns ( credentials , cnsConf , regionList , apigwOutputs )
214
222
}
215
223
@@ -239,13 +247,16 @@ class Express extends Component {
239
247
functionName : curState . functionName ,
240
248
namespace : curState . namespace
241
249
} )
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
+ }
249
260
}
250
261
removeHandlers . push ( handler ( ) )
251
262
}
@@ -263,4 +274,4 @@ class Express extends Component {
263
274
}
264
275
}
265
276
266
- module . exports = Express
277
+ module . exports = ServerlessComponent
0 commit comments