refactored plugin and auth init a bit, and fixed issue where successive reloads caused old login strategies to be inadvertently preserved

v1.18.x
Julian Lam 11 years ago
parent 5f2a66295c
commit 7597c654a0

@ -137,7 +137,6 @@ function start() {
upgrade.check(function(schema_ok) { upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) { if (schema_ok || nconf.get('check-schema') === false) {
sockets.init(webserver.server); sockets.init(webserver.server);
plugins.init();
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path')); nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));

@ -129,7 +129,7 @@ module.exports = function(app, data) {
app.use(middleware.processRender); app.use(middleware.processRender);
auth.initialize(app); auth.initialize(app, middleware);
routeCurrentTheme(app, data.currentThemeId, data.themesData); routeCurrentTheme(app, data.currentThemeId, data.themesData);
routeThemeScreenshots(app, data.themesData); routeThemeScreenshots(app, data.themesData);

@ -31,11 +31,15 @@ var fs = require('fs'),
Plugins.initialized = false; Plugins.initialized = false;
Plugins.init = function() { Plugins.init = function(nbbApp, nbbMiddleware) {
if (Plugins.initialized) { if (Plugins.initialized) {
return; return;
} }
app = nbbApp;
middleware = nbbMiddleware;
hotswap.prepare(nbbApp);
if (global.env === 'development') { if (global.env === 'development') {
winston.info('[plugins] Initializing plugins system'); winston.info('[plugins] Initializing plugins system');
} }
@ -62,12 +66,6 @@ var fs = require('fs'),
}); });
}; };
Plugins.prepareApp = function(nbbApp, nbbMiddleware) {
app = nbbApp;
middleware = nbbMiddleware;
hotswap.prepare(nbbApp);
};
Plugins.ready = function(callback) { Plugins.ready = function(callback) {
if (!Plugins.initialized) { if (!Plugins.initialized) {
emitter.once('plugins:loaded', callback); emitter.once('plugins:loaded', callback);
@ -124,24 +122,20 @@ var fs = require('fs'),
}; };
Plugins.reloadRoutes = function(callback) { Plugins.reloadRoutes = function(callback) {
if (!app || !middleware || !controllers) { var router = express.Router();
return; router.hotswapId = 'plugins';
} else { router.render = function() {
var router = express.Router(); app.render.apply(app, arguments);
router.hotswapId = 'plugins'; };
router.render = function() {
app.render.apply(app, arguments); // Deprecated as of v0.5.0, remove this hook call for NodeBB v0.6.0-1
}; Plugins.fireHook('action:app.load', router, middleware, controllers);
// Deprecated as of v0.5.0, remove this hook call for NodeBB v0.6.0-1 Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
Plugins.fireHook('action:app.load', router, middleware, controllers); hotswap.replace('plugins', router);
winston.info('[plugins] All plugins reloaded and rerouted');
Plugins.fireHook('static:app.load', router, middleware, controllers, function() { callback();
hotswap.replace('plugins', router); });
winston.info('[plugins] All plugins reloaded and rerouted');
callback();
});
}
}; };
Plugins.loadPlugin = function(pluginPath, callback) { Plugins.loadPlugin = function(pluginPath, callback) {

@ -138,25 +138,26 @@
}); });
} }
Auth.initialize = function(app) { Auth.initialize = function(app, middleware) {
app.use(passport.initialize()); app.use(passport.initialize());
app.use(passport.session()); app.use(passport.session());
Auth.app = app;
Auth.middleware = middleware;
}; };
Auth.get_login_strategies = function() { Auth.get_login_strategies = function() {
return login_strategies; return login_strategies;
}; };
Auth.registerApp = function(app, middleware) {
Auth.app = app;
Auth.middleware = middleware;
};
Auth.reloadRoutes = function(callback) { Auth.reloadRoutes = function(callback) {
var router = express.Router(); var router = express.Router();
router.hotswapId = 'auth'; router.hotswapId = 'auth';
plugins.ready(function() { plugins.ready(function() {
// Reset the registered login strategies
login_strategies.length = 0;
plugins.fireHook('filter:auth.init', login_strategies, function(err) { plugins.fireHook('filter:auth.init', login_strategies, function(err) {
if (err) { if (err) {
winston.error('filter:auth.init - plugin failure'); winston.error('filter:auth.init - plugin failure');

@ -207,7 +207,7 @@ module.exports = function(app, middleware) {
app.use(handleErrors); app.use(handleErrors);
// Add plugin routes // Add plugin routes
plugins.reloadRoutes(); plugins.init(app, middleware);
authRoutes.reloadRoutes(); authRoutes.reloadRoutes();
}; };

@ -62,8 +62,6 @@ if(nconf.get('ssl')) {
}, function(err, data) { }, function(err, data) {
middleware = middleware(app, data); middleware = middleware(app, data);
routes(app, middleware); routes(app, middleware);
plugins.prepareApp(app, middleware);
auth.registerApp(app, middleware);
if (err) { if (err) {
winston.error('Errors were encountered while attempting to initialise NodeBB.'); winston.error('Errors were encountered while attempting to initialise NodeBB.');

Loading…
Cancel
Save