mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
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:
@@ -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),
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -167,7 +167,7 @@ module.exports = function(app, middleware) {
|
||||
|
||||
|
||||
// Add plugin routes
|
||||
plugins.init(app, middleware);
|
||||
plugins.reloadRoutes();
|
||||
authRoutes.reloadRoutes();
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user