static:app.load change
-
static:app.load
is used by a lot of plugins to add new routes to express, so it affects a lot of plugins. Previously we were only passing in a router to this hook, now both the express app and the plugin router is passed in.Previous hook
Plugins.fireHook('static:app.load', router, middleware, controllers, function() {
Current hook
Plugins.fireHook('static:app.load', {app: app, router: router, middleware: middleware, controllers: controllers}, function() {
Sample plugin before update:
myPlugin.init = function(app, middleware, controllers, callback) { app.get('/mypluginroute', middleware.buildHeader, function(req, res, next) { res.render('sometemplate', {}); }); callback(); })
After update :
myPlugin.init = function(params, callback) { params.router.get('/mypluginroute', params.middleware.buildHeader, function(req, res, next) { res.render('sometemplate', {}); }); callback(); })
Relevant commit https://github.com/NodeBB/NodeBB/commit/41ae8b61a77d742d1930f675f664e8c1e90208b2
Also keep in mind
action:app.load
which is the older version ofstatic:app.load
is deprecated and will be removed when 0.6.0 is released. So make sure you usestatic:app.load
in your plugins. -
Here's an example of a plugin that was updated to handle this change:
0.6.0 compat · julianlam/nodebb-plugin-sso-github@9b8ad26
NodeBB Plugin that allows users to login/register via their GitHub account. - 0.6.0 compat · julianlam/nodebb-plugin-sso-github@9b8ad26
GitHub (github.com)
This plugin doesn't create its own routes, but if it did, it would call
.get()
/.post()
/etc routes fromdata.router
instead ofdata.app
. -
tldr; every plugin is broken.
-
@Schamper said:
tldr; every plugin is broken.
Only the ones that add routes. Some plugins are just parsing content and have no routes for example nodebb-plugin-mentions wasn't effected.
The core plugins are already updated to this new signature.
-
Sample adaption code:
if( app && app.router ){ callback = middleware; middleware = app.middleware; controllers = app.controllers; app = app.app; }