From 1ff55d564a2ba16c1fa63fde505e75dc94118120 Mon Sep 17 00:00:00 2001 From: Austin King <shout@ozten.com> Date: Tue, 27 Mar 2012 19:03:58 -0700 Subject: [PATCH] Reusing staticPath in compress worker and making prefix configurable, removing DRY violation per llyod --- bin/browserid | 2 +- lib/configuration.js | 4 ++++ scripts/compress-worker.js | 14 ++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/browserid b/bin/browserid index 77b89ecdb..6f23273cb 100755 --- a/bin/browserid +++ b/bin/browserid @@ -138,7 +138,7 @@ var static_root = path.join(__dirname, "..", "resources", "static"); app.use(cachify.setup(assets(config.get('supported_languages')), { - prefix: 'v', + prefix: config.get('cachify_prefix'), production: config.get('use_minified_resources'), root: static_root, })); diff --git a/lib/configuration.js b/lib/configuration.js index ab8ca1603..eca775e27 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -67,6 +67,10 @@ var conf = module.exports = convict({ doc: "The scheme of the public URL. Calculated from the latter.", format: "string", }, + cachify_prefix: { + doc: "The prefix for cachify hashes in URLs", + format: 'string = "v"' + }, use_minified_resources: { doc: "Should the server serve minified resources?", format: 'boolean = true', diff --git a/scripts/compress-worker.js b/scripts/compress-worker.js index 4ffb92333..4c9616bff 100644 --- a/scripts/compress-worker.js +++ b/scripts/compress-worker.js @@ -1,5 +1,6 @@ const cachify = require('connect-cachify'), +config = require('../lib/configuration.js'), fs = require('fs'), jsp = require("uglify-js").parser, logger = require('../lib/logging.js').logger, @@ -11,6 +12,12 @@ path = require('path'); function compressResource(staticPath, name, files, cb) { var orig_code = ""; var info = undefined; + + // Cachify only used in compress for CSS Images, so no asserts needed + cachify.setup({}, { + prefix: config.get('cachify_prefix'), + root: staticPath + }); function writeFile(final_code) { mkdirp(path.join(staticPath, path.dirname(name)), function (err) { if (err) cb(err); @@ -81,11 +88,6 @@ function compressResource(staticPath, name, files, cb) { isBuildNeeded(); } -var static_root = path.join(__dirname, '..', 'resources/static/'); -logger.info("cachify will look in " + static_root); -// Cachify only used in compress for CSS Images, so no asserts needed -cachify.setup({}, { prefix: 'v', root: static_root }); - function cachify_embedded (css_src) { return css_src.replace(/url\s*\(['"](.*)\s*['"]\s*\)/g, function (str, url) { // This will throw an error if url doesn't exist. This is good as we will @@ -105,4 +107,4 @@ process.on('message', function(m) { info: info }); }); -}); +}); \ No newline at end of file -- GitLab