1- const split = require ( 'lodash.split' ) ;
2-
31const getResourcesByName = ( name , serverless ) => {
42 let resourceKeys = Object . keys ( serverless . service . provider . compiledCloudFormationTemplate . Resources ) ;
53 for ( let resourceName of resourceKeys ) {
@@ -9,36 +7,14 @@ const getResourcesByName = (name, serverless) => {
97 }
108}
119
12- const getApiGatewayMethodNameFor = ( path , httpMethod ) => {
13- const pathElements = split ( path , '/' ) ;
14- pathElements . push ( httpMethod . toLowerCase ( ) ) ;
15- let gatewayResourceName = pathElements
16- . map ( element => {
17- element = element . toLowerCase ( ) ;
18- element = element . replaceAll ( '+' , '' ) ;
19- element = element . replaceAll ( '_' , '' ) ;
20- element = element . replaceAll ( '.' , '' ) ;
21- element = element . replaceAll ( '-' , 'Dash' ) ;
22- if ( element . startsWith ( '{' ) ) {
23- element = element . substring ( element . indexOf ( '{' ) + 1 , element . indexOf ( '}' ) ) + "Var" ;
24- }
25- //capitalize first letter
26- return element . charAt ( 0 ) . toUpperCase ( ) + element . slice ( 1 ) ;
27- } ) . reduce ( ( a , b ) => a + b ) ;
28-
29- gatewayResourceName = "ApiGatewayMethod" + gatewayResourceName ;
30- return gatewayResourceName ;
31- }
32-
3310const addPathParametersCacheConfig = ( settings , serverless ) => {
3411 for ( let endpointSettings of settings . endpointSettings ) {
3512 if ( ! endpointSettings . cacheKeyParameters ) {
3613 continue ;
3714 }
38- const resourceName = getApiGatewayMethodNameFor ( endpointSettings . path , endpointSettings . method ) ;
39- const method = getResourcesByName ( resourceName , serverless ) ;
15+ const method = getResourcesByName ( endpointSettings . gatewayResourceName , serverless ) ;
4016 if ( ! method ) {
41- serverless . cli . log ( `[serverless-api-gateway-caching] The method ${ resourceName } couldn't be found in the
17+ serverless . cli . log ( `[serverless-api-gateway-caching] The method ${ endpointSettings . gatewayResourceName } couldn't be found in the
4218 compiled CloudFormation template. Caching settings will not be updated for this endpoint.` ) ;
4319 continue ;
4420 }
@@ -74,11 +50,10 @@ const addPathParametersCacheConfig = (settings, serverless) => {
7450 method . Properties . Integration . CacheKeyParameters . push ( cacheKeyParameter . name )
7551 }
7652 }
77- method . Properties . Integration . CacheNamespace = `${ resourceName } CacheNS` ;
53+ method . Properties . Integration . CacheNamespace = `${ endpointSettings . gatewayResourceName } CacheNS` ;
7854 }
7955}
8056
8157module . exports = {
82- addPathParametersCacheConfig : addPathParametersCacheConfig ,
83- getApiGatewayMethodNameFor : getApiGatewayMethodNameFor
58+ addPathParametersCacheConfig : addPathParametersCacheConfig
8459}
0 commit comments