Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FIXED - Middleware loading order bug

  • Loading branch information...
commit 9db79fd2587528a4101a0f912368ab08485796fb 1 parent 9fe5618
@glesperance authored
Showing with 31 additions and 34 deletions.
  1. +29 −12 lib/client/client.js
  2. +2 −22 lib/loader.js
View
41 lib/client/client.js
@@ -586,6 +586,11 @@ function watchAndOptimize(path, dst_tmpdir, options_tmpdir, callback) {
* @param app {Object} The app object as returned by express, connect, or
* rocket.
*
+ * @param middlewares {Array<Function||Array<String, Function>>} An array of functions
+ * representing connect/express middlewares -- or -- an array of Array having a route
+ * string as its first element on which to restrict the application of the middleware
+ * that is provided as the second element of the array.
+ *
* @param client {Object} The FileEventEmitter object of the `client`
* folder.
*
@@ -596,6 +601,8 @@ exports.setup = function setup_client() {
var args = Array.prototype.slice.call(arguments)
, app = args.shift()
+ , middlewares = args.shift()
+
, client = args.shift()
, callback = args.pop()
@@ -635,6 +642,21 @@ exports.setup = function setup_client() {
*/
app.use('/js/rocket', gzip.staticGzip(path.join(__dirname, 'rocket-js')));
+ function doneCallback() {
+ if (middlewares) {
+ for (var i = 0, ii = middlewares.length; i < ii; i++) {
+ if ( Array.isArray(middlewares[i]) ) {
+ app.use(middlewares[i][0], middlewares[i][1]);
+
+ } else {
+ app.use(middlewares[i]);
+ }
+ }
+ }
+
+ callback.apply(this, arguments)
+ }
+
if (process.env['NODE_ENV'] === 'production') {
async.parallel([
@@ -671,7 +693,7 @@ exports.setup = function setup_client() {
, async.apply(watchAndExportConfig, require_js_config_path)
- ], callback);
+ ], doneCallback);
} else {
@@ -682,18 +704,13 @@ exports.setup = function setup_client() {
app.use('/js/' + CLIENT_VIEWS_DIR_NAME , express.static(client_views_tmpdir.path));
- async.parallel(
-
- [
- async.apply(setupDevModeViews, views_dir_path, client_views_tmpdir)
- , async.apply(watchAndExportConfig, require_js_config_path)
- ]
-
- , callback
-
- );
-
+ async.parallel([
+ async.apply(setupDevModeViews, views_dir_path, client_views_tmpdir)
+ , async.apply(watchAndExportConfig, require_js_config_path)
+ ], doneCallback);
}
+
+
}
View
24 lib/loader.js
@@ -72,35 +72,15 @@ exports.createServer = function createServer_rocket() {
}
- if (middlewares) {
-
- for (var i = 0, ii = middlewares.length; i < ii; i++) {
-
- if ( Array.isArray(middlewares[i]) ) {
-
- app.use(middlewares[i][0], middlewares[i][1]);
-
- } else {
-
- app.use(middlewares[i]);
-
- }
-
- }
-
- }
-
asyncFs.mapDir(
app_dir
- , [
-
- [ CLIENT_DIR_NAME , async.apply(client.setup, app) ]
+ , [ [ CLIENT_DIR_NAME , async.apply(client.setup, app, middlewares) ]
, [ CONTROLLERS_DIR_NAME , async.apply(controller.setup, app, routes) ]
- , [ EXPORTS_DIR_NAME , async.apply(xport.setup, app, options.nowjs) ]
+ , [ EXPORTS_DIR_NAME , async.apply(xport.setup, app, options.nowjs) ]
, [ VIEWS_DIR_NAME , async.apply(view.setup, app, routes) ]
Please sign in to comment.
Something went wrong with that request. Please try again.