serverless-api-gateway-caching
Advanced tools
Comparing version 1.1.1 to 1.1.2-rc1
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "serverless-api-gateway-caching", | ||
"version": "1.1.1", | ||
"version": "1.1.2-rc1", | ||
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.", | ||
@@ -5,0 +5,0 @@ "main": "src/apiGatewayCachingPlugin.js", |
@@ -0,0 +0,0 @@ # serverless-api-gateway-caching |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const updateStageCacheSettings = require('./stageCache'); | ||
const { outputRestApiIdTo } = require('./restApiId'); | ||
@@ -25,13 +26,9 @@ class ApiGatewayCachingPlugin { | ||
updateCloudFormationTemplate() { | ||
let restApiId = { | ||
Ref: 'ApiGatewayRestApi', | ||
}; | ||
if (this.serverless.service.provider.apiGateway && this.serverless.service.provider.apiGateway.restApiId) { | ||
restApiId = this.serverless.service.provider.apiGateway.restApiId | ||
this.thereIsARestApi = restApiExists(); | ||
if (!this.thereIsARestApi) { | ||
return; | ||
} | ||
this.serverless.service.provider.compiledCloudFormationTemplate.Outputs.RestApiIdForApiGwCaching = { | ||
Description: 'Rest API Id', | ||
Value: restApiId, | ||
}; | ||
outputRestApiIdTo(this.serverless); | ||
// if caching is not defined or disabled | ||
@@ -46,6 +43,17 @@ if (!this.settings.cachingEnabled) { | ||
updateStage() { | ||
if (!this.thereIsARestApi) { | ||
return; | ||
} | ||
return updateStageCacheSettings(this.settings, this.serverless); | ||
} | ||
restApiExists() { | ||
let resource = this.serverless.service.provider.compiledCloudFormationTemplate.Resources['ApiGatewayRestApi']; | ||
if (resource) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
module.exports = ApiGatewayCachingPlugin; |
@@ -0,0 +0,0 @@ const isEmpty = require('lodash.isempty'); |
@@ -0,0 +0,0 @@ const isEmpty = require('lodash.isempty'); |
const isEmpty = require('lodash.isempty'); | ||
const { retrieveRestApiId } = require('./restApiId'); | ||
const getRestApiId = async (settings, serverless) => { | ||
const stackName = serverless.providers.aws.naming.getStackName(settings.stage); | ||
let stack = await serverless.providers.aws.request('CloudFormation', 'describeStacks', { StackName: stackName }, | ||
settings.stage, | ||
settings.region | ||
); | ||
return stack.Stacks[0].Outputs | ||
.filter(output => output.OutputKey === 'RestApiIdForApiGwCaching') | ||
.map(output => output.OutputValue)[0]; | ||
} | ||
String.prototype.replaceAll = function (search, replacement) { | ||
@@ -122,3 +110,3 @@ let target = this; | ||
let restApiId = await getRestApiId(settings, serverless); | ||
let restApiId = await retrieveRestApiId(serverless, settings); | ||
@@ -125,0 +113,0 @@ let patchOps = createPatchForStage(settings); |
@@ -0,0 +0,0 @@ module.exports = { |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19261
10
349
2