Skip to content

Commit

Permalink
fix: support all parameters for apigw
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed Oct 12, 2020
1 parent cee8860 commit 5e22cf3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ inputs:
- http
- https
environment: release
serviceName: test
2 changes: 1 addition & 1 deletion serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: nextjs
version: 0.1.6
version: 0.1.7
author: 'Tencent Cloud, Inc.'
org: 'Tencent Cloud, Inc.'
description: Deploy a serverless Next.js application onto Tencent SCF and API Gateway.
Expand Down
2 changes: 1 addition & 1 deletion src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ServerlessComopnent extends Component {
environment: apigwOutput.environment,
url: `${getDefaultProtocol(inputs.protocols)}://${apigwOutput.subDomain}/${
apigwOutput.environment
}/`
}${apigwInputs.endpoints[0].path}`
}

if (apigwOutput.customDomains) {
Expand Down
37 changes: 25 additions & 12 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ const prepareStaticCdnInputs = async (instance, inputs, origin) => {

const prepareInputs = async (instance, credentials, inputs = {}) => {
// 对function inputs进行标准化
const tempFunctionConf = inputs.functionConf ? inputs.functionConf : {}
const tempFunctionConf = inputs.functionConf
? inputs.functionConf
: inputs.functionConfig
? inputs.functionConfig
: {}
const fromClientRemark = `tencent-${CONFIGS.compName}`
const regionList = inputs.region
? typeof inputs.region == 'string'
Expand Down Expand Up @@ -366,35 +370,44 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
}
}
if (tempFunctionConf.vpcConfig) {
functionConf.vpcConfig = inputs.functionConf.vpcConfig
functionConf.vpcConfig = tempFunctionConf.vpcConfig
}

// 对apigw inputs进行标准化
const tempApigwConf = inputs.apigatewayConf ? inputs.apigatewayConf : {}
const tempApigwConf = inputs.apigatewayConf
? inputs.apigatewayConf
: inputs.apigwConfig
? inputs.apigwConfig
: {}
const apigatewayConf = Object.assign(tempApigwConf, {
serviceId: inputs.serviceId,
serviceId: inputs.serviceId || tempApigwConf.serviceId,
region: regionList,
isDisabled: tempApigwConf.isDisabled === true,
fromClientRemark: fromClientRemark,
serviceName: inputs.serviceName || getDefaultServiceName(instance),
description: getDefaultServiceDescription(instance),
serviceName: inputs.serviceName || tempApigwConf.serviceName || getDefaultServiceName(instance),
serviceDesc: tempApigwConf.serviceDesc || getDefaultServiceDescription(instance),
protocols: tempApigwConf.protocols || ['http'],
environment: tempApigwConf.environment ? tempApigwConf.environment : 'release',
endpoints: [
customDomains: tempApigwConf.customDomains || []
})
if (!apigatewayConf.endpoints) {
apigatewayConf.endpoints = [
{
path: '/',
path: tempApigwConf.path || '/',
enableCORS: tempApigwConf.enableCORS,
serviceTimeout: tempApigwConf.serviceTimeout,
method: 'ANY',
apiName: tempApigwConf.apiName || 'index',
function: {
isIntegratedResponse: true,
functionName: functionConf.name,
functionNamespace: functionConf.namespace
functionNamespace: functionConf.namespace,
functionQualifier:
(tempApigwConf.function && tempApigwConf.function.functionQualifier) || '$LATEST'
}
}
],
customDomains: tempApigwConf.customDomains || []
})
]
}
if (tempApigwConf.usagePlan) {
apigatewayConf.endpoints[0].usagePlan = {
usagePlanId: tempApigwConf.usagePlan.usagePlanId,
Expand Down

0 comments on commit 5e22cf3

Please sign in to comment.