hapiest-cloudfront-url
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -16,3 +16,3 @@ 'use strict'; | ||
/** | ||
* @param {String} cloudfrontDomainName | ||
* @param {String} cloudfrontDomainName - note, cloudfrontDomainName can also include a path portion to support "local" CF distributions stored in a particular folder on localhost | ||
* @param {Boolean} enabled | ||
@@ -73,4 +73,4 @@ * @param {CloudfrontOrigin[]} origins | ||
isDistributionUrl(url) { | ||
const urlInfo = Url.parse(url); | ||
return urlInfo.host === this._cloudfrontDomainName; | ||
const urlNoProtocol = url.replace(/^(http:\/\/|https:\/\/|\/\/)/,''); | ||
return urlNoProtocol.startsWith(this._cloudfrontDomainName); | ||
} | ||
@@ -77,0 +77,0 @@ |
{ | ||
"name": "hapiest-cloudfront-url", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Maps origin URLs to an AWS Cloudfront distribution URL", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -98,2 +98,18 @@ 'use strict'; | ||
it('Should return true when the url matches distribution and false when it does not even for distributions with paths in the domain name', function() { | ||
const cfUrlService = CloudfrontUrlServiceFactory.create({ | ||
cloudfrontDomainName: 'localhost:3000/localstorage/public/images', | ||
enabled: true, | ||
origins: [{host: 'localhost', port: 3000, path: 'localstorage/bucket/public'}] | ||
}); | ||
const urlToCheck_true = 'http://localhost:3000/localstorage/public/images/folder/thumbnail.jpg'; | ||
const isDistributionUrl_true = cfUrlService.isDistributionUrl(urlToCheck_true); | ||
isDistributionUrl_true.should.be.True(); | ||
const urlToCheck_false = 'http://localhost:3000/localstorage/thumbnail.jpg'; | ||
const isDistributionUrl_false = cfUrlService.isDistributionUrl(urlToCheck_false); | ||
isDistributionUrl_false.should.be.False(); | ||
}); | ||
}); | ||
@@ -100,0 +116,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
371
65985