mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: allow plugins to define api routes
via new plugin hook static:api.routes
This commit is contained in:
@@ -112,7 +112,7 @@ module.exports = async function (app, middleware) {
|
|||||||
|
|
||||||
await plugins.reloadRoutes({ router: router });
|
await plugins.reloadRoutes({ router: router });
|
||||||
await authRoutes.reloadRoutes({ router: router });
|
await authRoutes.reloadRoutes({ router: router });
|
||||||
writeRoutes.reload({ router: router });
|
await writeRoutes.reload({ router: router });
|
||||||
addCoreRoutes(app, router, middleware);
|
addCoreRoutes(app, router, middleware);
|
||||||
|
|
||||||
winston.info('Routes added');
|
winston.info('Routes added');
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
|
const winston = require('winston');
|
||||||
|
const plugins = require('../../plugins');
|
||||||
const middleware = require('../../middleware');
|
const middleware = require('../../middleware');
|
||||||
const helpers = require('../../controllers/helpers');
|
const helpers = require('../../controllers/helpers');
|
||||||
|
|
||||||
const Write = module.exports;
|
const Write = module.exports;
|
||||||
|
|
||||||
Write.reload = (params) => {
|
Write.reload = async (params) => {
|
||||||
const router = params.router;
|
const router = params.router;
|
||||||
|
|
||||||
router.use('/api/v3', function (req, res, next) {
|
router.use('/api/v3', function (req, res, next) {
|
||||||
@@ -40,19 +42,17 @@ Write.reload = (params) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// This router is reserved exclusively for plugins to add their own routes into the write api plugin. Confused yet? :trollface:
|
/**
|
||||||
// var customRouter = require('express').Router();
|
* Plugins can add routes to the Write API by attaching a listener to the
|
||||||
// plugins.fireHook('filter:plugin.write-api.routes', {
|
* below hook. The hooks added to the passed-in router will be mounted to
|
||||||
// router: customRouter,
|
* `/api/v3/plugins`.
|
||||||
// apiMiddleware: apiMiddleware,
|
*/
|
||||||
// middleware: coreMiddleware,
|
const pluginRouter = require('express').Router();
|
||||||
// errorHandler: errorHandler
|
await plugins.fireHook('static:api.routes', {
|
||||||
// }, function (err, payload) {
|
router: pluginRouter,
|
||||||
// router.use('/', payload.router);
|
middleware,
|
||||||
|
helpers,
|
||||||
// router.use(function(req, res) {
|
});
|
||||||
// // Catch-all
|
winston.info(`[api] Adding ${pluginRouter.stack.length} route(s) to \`api/v3/plugins\``);
|
||||||
// errorHandler.respond(404, res);
|
router.use('/api/v3/plugins', pluginRouter);
|
||||||
// });
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user