mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
proof-of-concept for hot-swapping of routes
This commit is contained in:
@@ -6,13 +6,18 @@ var fs = require('fs'),
|
||||
winston = require('winston'),
|
||||
nconf = require('nconf'),
|
||||
semver = require('semver'),
|
||||
express = require('express'),
|
||||
|
||||
db = require('./database'),
|
||||
emitter = require('./emitter'),
|
||||
meta = require('./meta'),
|
||||
translator = require('../public/src/translator'),
|
||||
utils = require('../public/src/utils'),
|
||||
pkg = require('../package.json');
|
||||
hotswap = require('./hotswap'),
|
||||
pkg = require('../package.json'),
|
||||
|
||||
controllers = require('./controllers'),
|
||||
app, middleware;
|
||||
|
||||
(function(Plugins) {
|
||||
|
||||
@@ -57,6 +62,12 @@ 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);
|
||||
@@ -107,10 +118,29 @@ var fs = require('fs'),
|
||||
});
|
||||
|
||||
next();
|
||||
}
|
||||
},
|
||||
async.apply(Plugins.reloadRoutes)
|
||||
], callback);
|
||||
};
|
||||
|
||||
Plugins.reloadRoutes = function(callback) {
|
||||
if (!app || !middleware || !controllers) {
|
||||
return;
|
||||
} else {
|
||||
var router = express.Router();
|
||||
router.hotswapId = 'plugins';
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
Plugins.loadPlugin = function(pluginPath, callback) {
|
||||
fs.readFile(path.join(pluginPath, 'plugin.json'), function(err, data) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user