Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class ServerlessFullstackPlugin {
this.prepareCertificate(distributionConfig);
this.prepareWaf(distributionConfig);
this.prepareSinglePageApp(resources.Resources);
this.prepareRestrictedPaths(distributionConfig);
this.prepareS3(resources.Resources);
this.prepareMinimumProtocolVersion(distributionConfig);
this.prepareCompressWebContent(distributionConfig);
Expand Down Expand Up @@ -483,6 +484,28 @@ class ServerlessFullstackPlugin {
}
}

prepareRestrictedPaths(distributionConfig) {
const restrictedPaths = this.getConfig('restrictedPaths', null);

const behaviorTemplate = _.find(distributionConfig.CacheBehaviors, (cacheBehavior => {
return cacheBehavior.TargetOriginId === 'RestrictedPathTemplate';
}));

//Remove template
distributionConfig.CacheBehaviors = _.filter(distributionConfig.CacheBehaviors, (cacheBehavior => {
return cacheBehavior.TargetOriginId !== 'RestrictedPathTemplate';
}));

if (restrictedPaths !== null) {
this.serverless.cli.log(`Configuring distribution for restricted paths...`);
distributionConfig.CacheBehaviors = distributionConfig.CacheBehaviors
.concat(_.map(restrictedPaths, (restrictedPath) => {
return { ...behaviorTemplate, ...restrictedPath, TargetOriginId: 'WebApp',
TrustedSigners: [].concat(restrictedPath.TrustedSigners) };
}));
}
}

prepareS3(resources) {
const bucketName = this.getConfig('bucketName', null);

Expand Down
15 changes: 15 additions & 0 deletions lib/resources/resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ Resources:
TargetOriginId: ApiGateway
ViewerProtocolPolicy: https-only
PathPattern: api/*
- AllowedMethods:
- GET
- HEAD
- OPTIONS
## Compress web content: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html
Compress: true
## The origin id defined above
TargetOriginId: RestrictedPathTemplate
## Defining if and how the QueryString and Cookies are forwarded to the origin which in this case is S3
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
## The protocol that users can use to access the files in the origin. To allow HTTP use `allow-all`
ViewerProtocolPolicy: redirect-to-https
ViewerCertificate:
AcmCertificateArn: arn
SslSupportMethod: sni-only
Expand Down