Skip to content

Commit

Permalink
FIXED - Middleware loading order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Lesperance committed Apr 2, 2012
1 parent 9fe5618 commit 9db79fd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
41 changes: 29 additions & 12 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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()
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -671,7 +693,7 @@ exports.setup = function setup_client() {

, async.apply(watchAndExportConfig, require_js_config_path)

], callback);
], doneCallback);

} else {

Expand All @@ -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);

}



}
24 changes: 2 additions & 22 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ]

Expand Down

0 comments on commit 9db79fd

Please sign in to comment.