Skip to content

Commit 96e3158

Browse files
author
Andy Hahn
committed
Add defaultCacheBehavior from MadSkills-io#19
1 parent 8a15b08 commit 96e3158

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/MadSkills-io/fullstack-serverless/master/LICENSE)
66
[![npm downloads](https://img.shields.io/npm/dt/fullstack-serverless.svg?style=flat)](https://www.npmjs.com/package/fullstack-serverless)
77

8-
A [serverless](http://www.serverless.com) plugin that automatically creates an AWS CloudFront distribution that serves static web content from S3 and optionally routes API traffic
9-
to API Gateway.
8+
A [serverless](http://www.serverless.com) plugin that automatically creates an AWS CloudFront distribution that serves static web content from S3 and optionally routes API traffic to API Gateway.
109

1110
Home page - https://www.madskills.io/fullstack-serverless/
1211

@@ -17,9 +16,10 @@ Home page - https://www.madskills.io/fullstack-serverless/
1716
- No CORS needed
1817
- Enables CDN caching of resources - so you don't waste Lambda invocations or API Gateway traffic
1918
for serving static files (just [set Cache-Control headers](https://serverless.com/framework/docs/providers/aws/events/apigateway/#custom-response-headers) in API responses)
20-
- Much more CloudWatch statistics of API usage (like bandwidth metrics)
19+
- More CloudWatch statistics of API usage (like bandwidth metrics)
2120
- Real world [access log](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html) - out of the box, API Gateway currently does not provide any kind of real "apache-like" access logs for your invocations
2221
- [Web Application Firewall](https://aws.amazon.com/waf/) support - enable AWS WAF to protect your API from security threats
22+
- Can be used to manage S3 content and CloudFront without API Gateway by simply not defining any functions
2323

2424
## Before you begin
2525
* Install the serverless framework
@@ -502,6 +502,21 @@ Use this parameter if you want to add additional origins to the CloudFormation r
502502

503503
---
504504

505+
**defaultCacheBehavior**
506+
507+
_optional_, default: `not set`
508+
509+
```yaml
510+
custom:
511+
fullstack:
512+
...
513+
defaultCacheBehavior:
514+
MinTTL: 3600
515+
...
516+
```
517+
518+
---
519+
505520
**cacheBehaviors**
506521

507522
_optional_, default: `not set`

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class ServerlessFullstackPlugin {
149149
}
150150

151151
processDeployment() {
152+
152153
if(this.cliOptions['client-deploy'] !== false) {
153154
let region,
154155
distributionFolder,
@@ -348,7 +349,7 @@ class ServerlessFullstackPlugin {
348349
this.prepareSinglePageApp(resources.Resources);
349350
this.prepareS3(resources.Resources);
350351
this.prepareMinimumProtocolVersion(distributionConfig);
351-
this.prepareCompressWebContent(distributionConfig);
352+
this.prepareDefaultCacheBehavior(distributionConfig);
352353

353354
}
354355

@@ -532,10 +533,15 @@ class ServerlessFullstackPlugin {
532533
resources.WebAppS3Bucket.Properties.WebsiteConfiguration.ErrorDocument = errorDocument;
533534
}
534535

535-
prepareCompressWebContent(distributionConfig) {
536+
prepareDefaultCacheBehavior(distributionConfig) {
537+
const defaultCacheBehavior = this.getConfig('defaultCacheBehavior', {})
536538
const compressWebContent = this.getConfig('compressWebContent', true);
537539

538-
distributionConfig.DefaultCacheBehavior.Compress = compressWebContent;
540+
distributionConfig.DefaultCacheBehavior = Object.assign({},
541+
distributionConfig.DefaultCacheBehavior,
542+
defaultCacheBehavior,
543+
{ Compress: compressWebContent }
544+
);
539545
}
540546

541547
getBucketName(bucketName) {

0 commit comments

Comments
 (0)