Skip to content

Node.js based forum software built for the modern web

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

Julian Lam4fffe4da9475
diff --git a/src/meta.js b/src/meta.js
index 4aa65f6719..8624f63ed4 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -53,6 +53,7 @@ var async = require('async'),
async.series([
async.apply(plugins.clearRequireCache),
async.apply(plugins.reload),
+ async.apply(plugins.reloadRoutes),
function(next) {
async.parallel([
async.apply(Meta.js.minify, false),
diff --git a/src/plugins.js b/src/plugins.js
index 4dee3a79d9..a32403e2ab 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -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();
diff --git a/src/routes/index.js b/src/routes/index.js
index 56bd177205..fb7781bee7 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -167,7 +167,7 @@ module.exports = function(app, middleware) {
// Add plugin routes
- plugins.init(app, middleware);
+ plugins.reloadRoutes();
authRoutes.reloadRoutes();
};
diff --git a/src/webserver.js b/src/webserver.js
index bd4acb231f..8671209113 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -55,10 +55,21 @@ if(nconf.get('ssl')) {
async.apply(!skipLess ? meta.css.minify : meta.css.getFromFile),
async.apply(meta.sounds.init)
]);
+
+ plugins.fireHook('static:app.preload', {
+ app: app,
+ middleware: middleware
+ }, function(err) {
+ if (err) {
+ return winston.error('[plugins] Encountered error while executing pre-router plugins hooks: ' + err.message);
+ }
+
+ routes(app, middleware);
+ });
});
middleware = middleware(app);
- routes(app, middleware);
+ plugins.init(app, middleware);
// Load server-side template helpers
helpers.register();