diff --git a/app.js b/app.js index 52e3e000db..b47935376d 100644 --- a/app.js +++ b/app.js @@ -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')); diff --git a/src/middleware/index.js b/src/middleware/index.js index 986d5ffe91..f9ee6e4c01 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -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); diff --git a/src/plugins.js b/src/plugins.js index 427816c7bc..41f38dfd3c 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -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) { diff --git a/src/routes/authentication.js b/src/routes/authentication.js index e17289ba5c..cfe9e71462 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -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'); diff --git a/src/routes/index.js b/src/routes/index.js index 642b8c1b9d..253f00404a 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -207,7 +207,7 @@ module.exports = function(app, middleware) { app.use(handleErrors); // Add plugin routes - plugins.reloadRoutes(); + plugins.init(app, middleware); authRoutes.reloadRoutes(); }; diff --git a/src/webserver.js b/src/webserver.js index e51ffe1da9..d9d47d7f3c 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -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.');