Skip to content

Commit

Permalink
Merge branch 'release/1.5.1' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Ionita committed Oct 6, 2020
2 parents 444df4c + b0c4617 commit f583e46
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ functions:
- name: request.path.proxy
```
API Gateway will create cache entries like this:
- `GET /cats/davy/` will create a cache entry for `proxy=davy`
- `GET /cats/london/battersea/pink` will create an entry for `proxy=london/battersea/pink`
- `GET /cats/london/battersea/pink?type=animals` will only create an entry for `proxy=london/battersea/pink`, ignoring the query string.
- `GET /cats/toby/` will create a cache entry for `proxy=toby`
- `GET /cats/in/london` will create an entry for `proxy=in/london`
- `GET /cats/in/london?named=toby` will only create an entry for `proxy=in/london`, ignoring the query string. Note, however, that you can also add the `named` query string parameter as a cache key parameter and it will cache based on that value as well.


### Cache key parameters from the body
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-api-gateway-caching",
"version": "1.5.0",
"version": "1.5.1",
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.",
"main": "src/apiGatewayCachingPlugin.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/ApiGatewayCachingSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class ApiGatewayEndpointCachingSettings {
this.method = event.http.method;
}

if (this.path.endsWith('/') && this.path.length > 1) {
this.path = this.path.slice(0, -1);
}

if (!event.http.caching) {
this.cachingEnabled = false;
return;
Expand Down
33 changes: 33 additions & 0 deletions test/creating-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,39 @@ describe('Creating settings', () => {
});
});
});

// API Gateway's updateStage doesn't like paths which end in forward slash
describe('when a http endpoint path ends with a forward slash character and caching is turned on globally', () => {
before(() => {
endpoint = given.a_serverless_function('list-cats')
.withHttpEndpoint('get', '/cat/');
serverless = given.a_serverless_instance()
.withApiGatewayCachingConfig(true)
.withFunction(endpoint);

cacheSettings = createSettingsFor(serverless);
});

it('settings should contain the endpoint path without the forward slash at the end', () => {
expect(cacheSettings.endpointSettings[0].path).to.equal('/cat');
});
});

describe('when a http endpoint path is a forward slash character and caching is turned on globally', () => {
before(() => {
endpoint = given.a_serverless_function('list-cats')
.withHttpEndpoint('get', '/');
serverless = given.a_serverless_instance()
.withApiGatewayCachingConfig(true)
.withFunction(endpoint);

cacheSettings = createSettingsFor(serverless);
});

it('settings should contain the endpoint path as is', () => {
expect(cacheSettings.endpointSettings[0].path).to.equal('/');
});
});
});

const createSettingsFor = (serverless, options) => {
Expand Down

0 comments on commit f583e46

Please sign in to comment.