mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	refactored plugin and auth init a bit, and fixed issue where successive reloads caused old login strategies to be inadvertently preserved
This commit is contained in:
		
							
								
								
									
										1
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								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')); | ||||
|  | ||||
|   | ||||
| @@ -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,9 +122,6 @@ var fs = require('fs'), | ||||
| 	}; | ||||
|  | ||||
| 	Plugins.reloadRoutes = function(callback) { | ||||
| 		if (!app || !middleware || !controllers) { | ||||
| 			return; | ||||
| 		} else { | ||||
| 		var router = express.Router(); | ||||
| 		router.hotswapId = 'plugins'; | ||||
| 		router.render = function() { | ||||
| @@ -141,7 +136,6 @@ var fs = require('fs'), | ||||
| 			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.'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user