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 10 years ago
parent 5f2a66295c
commit 7597c654a0

@ -137,7 +137,6 @@ function start() {
upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) {
sockets.init(webserver.server);
plugins.init();
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);
auth.initialize(app);
auth.initialize(app, middleware);
routeCurrentTheme(app, data.currentThemeId, data.themesData);
routeThemeScreenshots(app, data.themesData);

@ -31,11 +31,15 @@ var fs = require('fs'),
Plugins.initialized = false;
Plugins.init = function() {
Plugins.init = function(nbbApp, nbbMiddleware) {
if (Plugins.initialized) {
return;
}
app = nbbApp;
middleware = nbbMiddleware;
hotswap.prepare(nbbApp);
if (global.env === 'development') {
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) {
if (!Plugins.initialized) {
emitter.once('plugins:loaded', callback);
@ -124,24 +122,20 @@ var fs = require('fs'),
};
Plugins.reloadRoutes = function(callback) {
if (!app || !middleware || !controllers) {
return;
} else {
var router = express.Router();
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);
Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
hotswap.replace('plugins', router);
winston.info('[plugins] All plugins reloaded and rerouted');
callback();
});
}
var router = express.Router();
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);
Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
hotswap.replace('plugins', router);
winston.info('[plugins] All plugins reloaded and rerouted');
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.session());
Auth.app = app;
Auth.middleware = middleware;
};
Auth.get_login_strategies = function() {
return login_strategies;
};
Auth.registerApp = function(app, middleware) {
Auth.app = app;
Auth.middleware = middleware;
};
Auth.reloadRoutes = function(callback) {
var router = express.Router();
router.hotswapId = 'auth';
plugins.ready(function() {
// Reset the registered login strategies
login_strategies.length = 0;
plugins.fireHook('filter:auth.init', login_strategies, function(err) {
if (err) {
winston.error('filter:auth.init - plugin failure');

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

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

Loading…
Cancel
Save