electricity
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -27,2 +27,6 @@ const crypto = require('crypto'); | ||
if (!('hashify' in options)) { | ||
options.hashify = true; | ||
} | ||
if (!options.sass) { | ||
@@ -178,2 +182,8 @@ options.sass = {}; | ||
function dehashifyPath(filePath) { | ||
if (!options.hashify) { | ||
return { | ||
path: filePath, | ||
hash: undefined | ||
} | ||
} | ||
var hashRegex = /-[0-9a-f]+(\.[^\.]*$)/; | ||
@@ -184,4 +194,4 @@ var hashMatch = filePath.match(hashRegex); | ||
return { | ||
path: hash.length==32 ? filePath.replace(hashRegex, '$1') : filePath, | ||
hash: hash.length==32 ? hash : null | ||
path: hash.length == 32 ? filePath.replace(hashRegex, '$1') : filePath, | ||
hash: hash.length == 32 ? hash : null | ||
}; | ||
@@ -211,3 +221,3 @@ } | ||
if(filename[0] === '/') { | ||
if (filename[0] === '/') { | ||
file = files[filename]; | ||
@@ -221,3 +231,3 @@ } else { | ||
if (file) { | ||
return 'url(' + urlBuilder(filename, file.hash) + ')'; // Add hash | ||
return 'url(' + urlBuilder(filename) + ')'; // Add hash | ||
} | ||
@@ -230,2 +240,5 @@ | ||
function hashifyPath(filePath, hash) { | ||
if (!options.hashify) { | ||
return filePath; | ||
} | ||
if (filePath.indexOf('.') != -1) { | ||
@@ -313,4 +326,8 @@ return filePath.replace(/\.([^\.]*)([?#].*)?$/, '-' + hash + '.$1$2'); | ||
if (file) { | ||
var uri = hashifyPath(prefixSlash(filePath), file.hash); | ||
var uri = prefixSlash(filePath); | ||
if (options.hashify) { | ||
uri = hashifyPath(uri, file.hash); | ||
} | ||
if (options && options.hostname) { | ||
@@ -388,3 +405,3 @@ uri = '//' + options.hostname + uri; | ||
// Verify file matches the requested hash, otherwise 302 | ||
if (reqInfo.hash !== file.hash) { | ||
if (options.hashify && reqInfo.hash !== file.hash) { | ||
res.set({ | ||
@@ -391,0 +408,0 @@ 'Cache-Control': 'no-cache', |
@@ -38,3 +38,3 @@ { | ||
}, | ||
"version": "1.6.0" | ||
"version": "1.7.0" | ||
} |
@@ -71,2 +71,3 @@ Electricity | ||
var options = { | ||
hashify: true, | ||
headers: {}, | ||
@@ -92,2 +93,3 @@ hostname: '', | ||
var options = { | ||
hashify: false, // Do not generate hashes for URLs | ||
headers: { 'Access-Control-Allow-Origin': 'http://foo.example' }, | ||
@@ -94,0 +96,0 @@ hostname: 'cdn.example.com', // CDN hostname |
Sorry, the diff of this file is too big to display
119110
2239
173