Skip to content

Made 'originPath' configurable #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ plugins:
custom:
apiCloudFront:
domain: my-custom-domain.com
originPath: /some-path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get some additional description about this field? :)

certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
waf: 00000000-0000-0000-0000-000000000000
compress: true
Expand Down
23 changes: 18 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @Date: 2018-08-15T23:22:05+02:00
* @Last modified time: 2018-08-16T18:23:33+02:00
*/



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, get rid of this meta data :)

const path = require('path');
const _ = require('lodash');
const chalk = require('chalk');
Expand Down Expand Up @@ -98,7 +105,13 @@ class ServerlessApiCloudFrontPlugin {
}

prepareOrigins(distributionConfig) {
distributionConfig.Origins[0].OriginPath = `/${this.options.stage}`;
const originPath = this.getConfig('originPath', `/${this.options.stage}`);

if (originPath !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparison will always be true as getConfig returns default value in case of originPath missing in config.

I would suggest to get rid of it :)

distributionConfig.Origins[0].OriginPath = originPath;
} else {
delete distributionConfig.Origins[0].OriginPath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else block will:

  • never be called
  • will ruin backward compatibility if will be called in any particular way

Please, get rid of it :)

}
}

prepareCookies(distributionConfig) {
Expand All @@ -108,10 +121,10 @@ class ServerlessApiCloudFrontPlugin {
distributionConfig.DefaultCacheBehavior.ForwardedValues.Cookies.WhitelistedNames = forwardCookies;
}
}

prepareHeaders(distributionConfig) {
const forwardHeaders = this.getConfig('headers', 'none');

if (Array.isArray(forwardHeaders)) {
distributionConfig.DefaultCacheBehavior.ForwardedValues.Headers = forwardHeaders;
} else {
Expand All @@ -121,7 +134,7 @@ class ServerlessApiCloudFrontPlugin {

prepareQueryString(distributionConfig) {
const forwardQueryString = this.getConfig('querystring', 'all');

if (Array.isArray(forwardQueryString)) {
distributionConfig.DefaultCacheBehavior.ForwardedValues.QueryString = true;
distributionConfig.DefaultCacheBehavior.ForwardedValues.QueryStringCacheKeys = forwardQueryString;
Expand Down Expand Up @@ -154,7 +167,7 @@ class ServerlessApiCloudFrontPlugin {
delete distributionConfig.WebACLId;
}
}

prepareCompress(distributionConfig) {
distributionConfig.DefaultCacheBehavior.Compress = (this.getConfig('compress', false) === true) ? true : false;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"chalk": "^2.0.0",
"js-yaml": "^3.10.0",
"lodash": "^4.13.1"
}
},
"devDependencies": {}
}