From 82447dd2bc537abe37c6c526ed3a8ff1a9c8994b Mon Sep 17 00:00:00 2001 From: choxnox Date: Wed, 15 Aug 2018 23:19:32 +0200 Subject: [PATCH 1/4] Made 'originPath' configurable --- index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index dfe3337..3cd4ca1 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,10 @@ +/** + * @Date: 2018-08-15T23:14:31+02:00 + * @Last modified time: 2018-08-15T23:18:09+02:00 + */ + + + const path = require('path'); const _ = require('lodash'); const chalk = require('chalk'); @@ -98,7 +105,8 @@ class ServerlessApiCloudFrontPlugin { } prepareOrigins(distributionConfig) { - distributionConfig.Origins[0].OriginPath = `/${this.options.stage}`; + const originPath = this.getConfig('originPath', `/${this.options.stage}`); + distributionConfig.Origins[0].OriginPath = originPath; } prepareCookies(distributionConfig) { @@ -108,10 +116,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 { @@ -121,7 +129,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; @@ -154,7 +162,7 @@ class ServerlessApiCloudFrontPlugin { delete distributionConfig.WebACLId; } } - + prepareCompress(distributionConfig) { distributionConfig.DefaultCacheBehavior.Compress = (this.getConfig('compress', false) === true) ? true : false; } From 4f8918c868a361d99cc0ec5a3500d623046aa4b4 Mon Sep 17 00:00:00 2001 From: Amir Ahmetovic Date: Wed, 15 Aug 2018 23:21:13 +0200 Subject: [PATCH 2/4] Removed autogenerated file header --- index.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/index.js b/index.js index 3cd4ca1..f3ec6ba 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,3 @@ -/** - * @Date: 2018-08-15T23:14:31+02:00 - * @Last modified time: 2018-08-15T23:18:09+02:00 - */ - - - const path = require('path'); const _ = require('lodash'); const chalk = require('chalk'); From 9dd19df3d01f8a7904d17cfd5d35b16671afabe7 Mon Sep 17 00:00:00 2001 From: choxnox Date: Wed, 15 Aug 2018 23:21:43 +0200 Subject: [PATCH 3/4] Added 'originPath' to the sample serverless.yml --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2ecf842..23ee818 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ plugins: custom: apiCloudFront: domain: my-custom-domain.com + originPath: /some-path certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444 waf: 00000000-0000-0000-0000-000000000000 compress: true From fa203fbfe491bbd7dba6f28668e9aa486e11cb0c Mon Sep 17 00:00:00 2001 From: choxnox Date: Thu, 16 Aug 2018 18:24:20 +0200 Subject: [PATCH 4/4] Fixed a bug when 'originPath' was 'null' --- index.js | 14 +++++++++++++- package.json | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f3ec6ba..85bc6fd 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,10 @@ +/** + * @Date: 2018-08-15T23:22:05+02:00 + * @Last modified time: 2018-08-16T18:23:33+02:00 + */ + + + const path = require('path'); const _ = require('lodash'); const chalk = require('chalk'); @@ -99,7 +106,12 @@ class ServerlessApiCloudFrontPlugin { prepareOrigins(distributionConfig) { const originPath = this.getConfig('originPath', `/${this.options.stage}`); - distributionConfig.Origins[0].OriginPath = originPath; + + if (originPath !== null) { + distributionConfig.Origins[0].OriginPath = originPath; + } else { + delete distributionConfig.Origins[0].OriginPath; + } } prepareCookies(distributionConfig) { diff --git a/package.json b/package.json index 1c54598..334f680 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,6 @@ "chalk": "^2.0.0", "js-yaml": "^3.10.0", "lodash": "^4.13.1" - } + }, + "devDependencies": {} }