moved plugin route reloading outside of plugin initialisation, so plugins can add a hook listener before core routes have been added

This commit is contained in:
Julian Lam
2015-04-16 14:26:58 -04:00
parent 617808d574
commit 4fffe4da94
4 changed files with 21 additions and 5 deletions

View File

@@ -120,19 +120,23 @@ var fs = require('fs'),
});
next();
},
async.apply(Plugins.reloadRoutes)
}
], callback);
};
Plugins.reloadRoutes = function(callback) {
callback = callback || function() {};
var router = express.Router();
router.hotswapId = 'plugins';
router.render = function() {
app.render.apply(app, arguments);
};
Plugins.fireHook('static:app.load', {app: app, router: router, middleware: middleware, controllers: controllers}, function() {
Plugins.fireHook('static:app.load', {app: app, router: router, middleware: middleware, controllers: controllers}, function(err) {
if (err) {
return winston.error('[plugins] Encountered error while executing post-router plugins hooks: ' + err.message);
}
hotswap.replace('plugins', router);
winston.verbose('[plugins] All plugins reloaded and rerouted');
callback();