Skip to content

Commit

Permalink
feat: support disable creating apigw
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed May 9, 2020
1 parent 0415b5f commit 87e2499
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"download": "^8.0.0",
"fs-extra": "^8.1.0",
"tencent-component-toolkit": "^1.2.3",
"tencent-component-toolkit": "^1.4.3",
"type": "^2.0.0"
}
}
42 changes: 27 additions & 15 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class ServerlessComopnent extends Component {
}

async deployApigateway(credentials, inputs, regionList) {
if (inputs.isDisabled) {
return {}
}
const apigw = new MultiApigw(credentials, regionList)
inputs.oldState = {
apiList: (this.state[regionList[0]] && this.state[regionList[0]].apiList) || []
Expand Down Expand Up @@ -178,7 +181,6 @@ class ServerlessComopnent extends Component {
async deploy(inputs) {
console.log(`Deploying ${CONFIGS.frameworkFullname} App...`)

// get credentials
const credentials = this.getCredentials()

// 对Inputs内容进行标准化
Expand All @@ -188,15 +190,20 @@ class ServerlessComopnent extends Component {
inputs
)

// deploy scf + apigw
// 部署函数 + API网关
const outputs = {}
if (!functionConf.code.src) {
outputs.templateUrl = CONFIGS.templateUrl
}
const [apigwOutputs, functionOutputs] = await Promise.all([
this.deployApigateway(credentials, apigatewayConf, regionList, outputs),
this.deployFunction(credentials, functionConf, regionList, outputs)
])

const deployTasks = [this.deployFunction(credentials, functionConf, regionList, outputs)]
// support apigatewayConf.isDisabled
if (apigatewayConf.isDisabled !== true) {
deployTasks.push(this.deployApigateway(credentials, apigatewayConf, regionList, outputs))
} else {
this.state.apigwDisabled = true
}
const [functionOutputs, apigwOutputs = {}] = await Promise.all(deployTasks)

// optimize outputs for one region
if (regionList.length === 1) {
Expand All @@ -209,8 +216,8 @@ class ServerlessComopnent extends Component {
outputs['scf'] = functionOutputs
}

// add cns for apigw
if (cnsConf.length > 0) {
// cns depends on apigw, so if disabled apigw, just ignore it.
if (cnsConf.length > 0 && apigatewayConf.isDisabled !== true) {
outputs['cns'] = await this.deployCns(credentials, cnsConf, regionList, apigwOutputs)
}

Expand All @@ -226,7 +233,9 @@ class ServerlessComopnent extends Component {

const { state } = this
const { regionList = [] } = state

const credentials = this.getCredentials()

const removeHandlers = []
for (let i = 0; i < regionList.length; i++) {
const curRegion = regionList[i]
Expand All @@ -238,13 +247,16 @@ class ServerlessComopnent extends Component {
functionName: curState.functionName,
namespace: curState.namespace
})
await apigw.remove({
created: curState.created,
environment: curState.environment,
serviceId: curState.serviceId,
apiList: curState.apiList,
customDomains: curState.customDomains
})
// if disable apigw, no need to remove
if (state.apigwDisabled !== true) {
await apigw.remove({
created: curState.created,
environment: curState.environment,
serviceId: curState.serviceId,
apiList: curState.apiList,
customDomains: curState.customDomains
})
}
}
removeHandlers.push(handler())
}
Expand Down

0 comments on commit 87e2499

Please sign in to comment.