From 8f27d7810b92912c252edf6716887b93e1c254a8 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Thu, 9 Feb 2017 15:50:05 -0700
Subject: [PATCH 1/2] Ajaxify improvement, `/assets/uploads`
---
public/src/ajaxify.js | 67 +++++++++++++++++-----------------------
src/controllers/index.js | 2 +-
2 files changed, 29 insertions(+), 40 deletions(-)
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index 6b18e5dda0..4e1a576035 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -249,48 +249,37 @@ $(document).ready(function () {
$(window).trigger('action:script.load', data);
// Require and parse modules
- var outstanding = 0;
- var onReady = function () {
- if (outstanding) {
- return setTimeout(onReady, 100);
+ var outstanding = data.scripts.length;
+
+ data.scripts.map(function (script) {
+ if (typeof script === 'function') {
+ return function (next) {
+ script();
+ next();
+ };
}
-
- data.scripts = data.scripts.filter(Boolean);
- data.scripts.forEach(function (functionRef) {
- functionRef();
- });
-
- callback();
- };
-
- data.scripts.forEach(function (script, idx) {
- switch (typeof script) {
- case 'string':
- ++outstanding;
- (function (idx) {
- require([script], function (script) {
- if (script && script.init) {
- data.scripts[idx] = script.init;
- } else {
- data.scripts[idx] = null;
- }
- --outstanding;
- });
- }(idx));
- break;
-
- case 'function':
- // No changes needed
- break;
-
- default:
- // Neither? No comprende
- data.scripts[idx] = undefined;
- break;
+ if (typeof script === 'string') {
+ return function (next) {
+ require([script], function (script) {
+ if (script && script.init) {
+ script.init();
+ }
+ next();
+ }, function () {
+ // ignore 404 error
+ next();
+ });
+ };
}
+ return null;
+ }).filter(Boolean).forEach(function (fn) {
+ fn(function () {
+ outstanding -= 1;
+ if (outstanding === 0) {
+ callback();
+ }
+ });
});
-
- onReady();
};
ajaxify.loadData = function (url, callback) {
diff --git a/src/controllers/index.js b/src/controllers/index.js
index 7d6666f8da..800559db4b 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -365,7 +365,7 @@ Controllers.handle404 = function (req, res) {
if (isClientScript.test(req.url)) {
res.type('text/javascript').status(200).send('');
- } else if (req.path.startsWith(relativePath + '/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') {
+ } else if (req.path.startsWith(relativePath + '/assets/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') {
meta.errors.log404(req.path || '');
res.sendStatus(404);
} else if (req.accepts('html')) {
From b553236620c758abb6573be040a0398d06b0735f Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Fri, 10 Feb 2017 21:18:09 -0700
Subject: [PATCH 2/2] Better defaults if cache buster read fails
---
src/meta/cacheBuster.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/meta/cacheBuster.js b/src/meta/cacheBuster.js
index ca00fba057..461bcaf801 100644
--- a/src/meta/cacheBuster.js
+++ b/src/meta/cacheBuster.js
@@ -32,15 +32,15 @@ exports.read = function read(callback) {
fs.readFile(filePath, function (err, buffer) {
if (err) {
winston.warn('[cache-buster] could not read cache buster: ' + err.message);
- return callback();
+ return callback(null, generate());
}
- buffer = buffer.toString();
- if (buffer) {
- cached = buffer;
- return callback(null, cached);
+ if (!buffer || buffer.toString().length !== 11) {
+ winston.warn('[cache-buster] cache buster string invalid: expected /[a-z0-9]{11}/, got `' + buffer + '`');
+ return callback(null, generate());
}
- callback();
+ cached = buffer.toString();
+ callback(null, cached);
});
};