Permalink
Browse files

cache busting: add 'enable_code_version' configuration - when true re…

…turn 'code_version' in session_context - also /production/XXX_vYYY.{js,css} calls now map back to /production/XXX.{js,css} - issue #226
  • Loading branch information...
1 parent 706b38d commit 22583d02f34882c8c17a2a6fe3ece90ec456bdb0 @lloyd lloyd committed Jan 17, 2012
View
17 lib/browserid/views.js
@@ -2,7 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-const metrics = require('../metrics.js');
+const
+metrics = require('../metrics.js'),
+url = require('url'),
+logger = require('../logging.js').logger;
// all templated content, redirects, and renames are handled here.
// anything that is not an api, and not static
@@ -140,4 +143,16 @@ exports.setup = function(app) {
app.get("/.well-known/browserid", function(req, res) {
res.json({ 'public-key': publicKey.toSimpleObject() });
});
+
+ // now for static redirects for cach busting - issue #225
+ var versionRegex = /^(\/production\/[a-zA-Z\-]+)_v[a-zA-Z0-9]{7}(\.(?:css|js))$/;
+ app.use(function(req, res, next) {
+ var m = versionRegex.exec(req.url);
+ if (m) {
+ var newURL = m[1] + m[2];
+ logger.debug('internal redirect of ' + req.url + ' to ' + newURL);
+ req.url = newURL;
+ }
+ next();
+ });
};
View
12 lib/configuration.js
@@ -78,7 +78,10 @@ g_configs.production = {
max_compute_processes: undefined,
// return a 503 if a compute process would take over 10s to complete
max_compute_duration: 10,
- disable_primary_support: true
+ disable_primary_support: true,
+ // code_version is a property in the session_context response... When
+ // enabled it causes frontend code to employ cache busting logic. issue #226
+ enable_code_version: false
/*
, http_proxy: {
port: 3128,
@@ -91,7 +94,7 @@ g_configs.production = {
g_configs.local = {
URL: 'http://127.0.0.1:10002',
email_to_console: true, // don't send email, just dump verification URLs to console.
- use_minified_resources: false,
+ use_minified_resources: true,
var_path: path.join(__dirname, "..", "var"),
database: {
driver: "json",
@@ -103,7 +106,10 @@ g_configs.local = {
min_time_between_emails_ms: g_configs.production.min_time_between_emails_ms,
max_compute_processes: undefined,
max_compute_duration: 10,
- disable_primary_support: false
+ disable_primary_support: false,
+ // code_version is a property in the session_context response... When
+ // enabled it causes frontend code to employ cache busting logic. issue #226
+ enable_code_version: false
/*
, http_proxy: {
port: 3128,
View
17 lib/version.js
@@ -28,26 +28,27 @@ try {
}
// now set the SHA to either the read SHA or a random string
-module.exports = sha ? sha : secrets.weakGenerate(7);
+module.exports = function() { return sha; }
// if ver.txt discovery failed, try using git to get the sha.
if (!sha) {
+ sha = secrets.weakGenerate(7);
+
// next try using git
var p = spawn('git', [ 'log', '--pretty=%h', '-1' ]);
var buf = "";
p.stdout.on('data', function(d) {
buf += d;
});
p.on('exit', function(code, signal) {
- var sha = buf.toString().trim();
- if (sha && sha.length === 7) {
- module.exports = sha;
- logger.info('code version (via git) is: ' + module.exports);
+ var gitsha = buf.toString().trim();
+ if (gitsha && gitsha.length === 7) {
+ sha = gitsha
+ logger.info('code version (via git) is: ' + module.exports());
} else {
- logger.warn('code version (randomly generated) is: ' + module.exports);
+ logger.warn('code version (randomly generated) is: ' + module.exports());
}
});
} else {
- logger.info('code version (from ver.txt) is: ' + module.exports);
+ logger.info('code version (from ver.txt) is: ' + module.exports());
}
-
View
11 lib/wsapi/session_context.js
@@ -7,7 +7,8 @@ db = require('../db.js'),
logger = require('../logging.js').logger,
crypto = require('crypto'),
wsapi = require('../wsapi.js'),
-secrets = require('../secrets.js');
+secrets = require('../secrets.js'),
+version = require('../version.js');
// return the CSRF token, authentication status, and current server time (for assertion signing)
// 2011-12-22: adding a random seed for keygen
@@ -37,14 +38,18 @@ exports.process = function(req, res) {
var authenticated = false;
function sendResponse() {
- res.json({
+ var respObj = {
csrf_token: req.session.csrf,
server_time: (new Date()).getTime(),
authenticated: authenticated,
auth_level: auth_level,
domain_key_creation_time: domainKeyCreationDate.getTime(),
random_seed: crypto.randomBytes(32).toString('base64')
- });
+ };
+ if (config.get('enable_code_version')) {
+ respObj.code_version = version();
+ }
+ res.json(respObj);
};
// if they're authenticated for an email address that we don't know about,
View
2 resources/static/dialog/controllers/code_check.js
@@ -35,7 +35,7 @@ BrowserID.Modules.CodeCheck = (function() {
function loadScript(version, oncomplete) {
var script = document.createElement("script");
script.type = "text/javascript";
- script.src = "https://browserid.org/dialog/production_v" + version + ".js";
+ script.src = "https://browserid.org/production/dialog_v" + version + ".js";
document.head.appendChild(script);
oncomplete();
View
2 resources/static/include.js
View
2 tests/software-version-test.js
@@ -19,7 +19,7 @@ suite.options.error = false;
suite.addBatch({
"version": {
- topic: function() { return version; },
+ topic: function() { return version(); },
"works": function(r) {
assert.isString(r);
assert.equal(r.length, 7);

0 comments on commit 22583d0

Please sign in to comment.