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 diff --git a/index.js b/index.js index dfe3337..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'); @@ -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) { + distributionConfig.Origins[0].OriginPath = originPath; + } else { + delete distributionConfig.Origins[0].OriginPath; + } } prepareCookies(distributionConfig) { @@ -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 { @@ -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; @@ -154,7 +167,7 @@ class ServerlessApiCloudFrontPlugin { delete distributionConfig.WebACLId; } } - + prepareCompress(distributionConfig) { distributionConfig.DefaultCacheBehavior.Compress = (this.getConfig('compress', false) === true) ? true : false; } 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": {} }