diff --git a/.sonarcloud.properties b/.sonarcloud.properties deleted file mode 100644 index 8b137891..00000000 --- a/.sonarcloud.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/Globals.ts b/src/Globals.ts index 5cff8a11..3ca0b55d 100644 --- a/src/Globals.ts +++ b/src/Globals.ts @@ -22,6 +22,11 @@ export default class Globals { websocket: "WEBSOCKET", }; + public static gatewayAPIIdKeys = { + [Globals.apiTypes.rest]: "restApiId", + [Globals.apiTypes.websocket]: "websocketApiId", + }; + public static tlsVersions = { tls_1_0: "TLS_1_0", tls_1_2: "TLS_1_2", diff --git a/src/index.ts b/src/index.ts index bc60fb5e..d78ebbe0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -523,17 +523,18 @@ class ServerlessCustomDomain { * Gets rest API id from existing config or CloudFormation stack */ public async getApiId(domain: DomainConfig): Promise { - const apiGateway = this.serverless.service.provider.apiGateway; - if (apiGateway && apiGateway.restApiId) { - const restApiId = apiGateway.restApiId; + const apiGateway = this.serverless.service.provider.apiGateway || {}; + const apiIdKey = Globals.gatewayAPIIdKeys[domain.apiType]; + const apiId = apiGateway[apiIdKey]; + if (apiId) { // if string value exists return the value - if (typeof restApiId === "string") { - Globals.logInfo(`Mapping custom domain to existing API ${restApiId}.`); - return restApiId; + if (typeof apiId === "string") { + Globals.logInfo(`Mapping custom domain to existing API ${apiId}.`); + return apiId; } // in case object and Fn::ImportValue try to get restApiId from the CloudFormation exports - if (typeof restApiId === "object" && restApiId["Fn::ImportValue"]) { - const importName = restApiId["Fn::ImportValue"]; + if (typeof apiId === "object" && apiId["Fn::ImportValue"]) { + const importName = apiId["Fn::ImportValue"]; let importValues; try { importValues = await this.cloudFormationWrapper.getImportValues([importName]); diff --git a/src/types.ts b/src/types.ts index a7e2d974..0e344d94 100644 --- a/src/types.ts +++ b/src/types.ts @@ -27,6 +27,7 @@ export interface ServerlessInstance { // tslint:disable-line }, apiGateway: { restApiId: string, + websocketApiId: string, }, } custom: { diff --git a/test/unit-tests/index.test.ts b/test/unit-tests/index.test.ts index d2f20b81..7817f43d 100644 --- a/test/unit-tests/index.test.ts +++ b/test/unit-tests/index.test.ts @@ -90,6 +90,7 @@ const constructPlugin = (customDomainOptions, multiple: boolean = false) => { provider: { apiGateway: { restApiId: null, + websocketApiId: null, }, compiledCloudFormationTemplate: { Outputs: null,