allow plugins to implements its own API, fix #283
This commit is contained in:
@@ -32,6 +32,22 @@ const pluginController = {
|
||||
res.json()
|
||||
},
|
||||
|
||||
async routeAPI (req, res, next) {
|
||||
const pluginName = req.params.plugin
|
||||
const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName)
|
||||
if (!plugin) {
|
||||
log.warn(`Plugin ${pluginName} not found`)
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
if (typeof plugin.routeAPI !== 'function') {
|
||||
log.warn(`Plugin ${pluginName} does not expose a 'routeAPI' function`)
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
return plugin.routeAPI(req, res, next)
|
||||
},
|
||||
|
||||
async testPlugin (req, res) {
|
||||
const pluginName = req.params.plugin
|
||||
const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName)
|
||||
|
||||
@@ -222,6 +222,8 @@ module.exports = () => {
|
||||
api.post('/plugin/test/:plugin', isAdmin, pluginController.testPlugin)
|
||||
api.put('/plugin/:plugin', isAdmin, pluginController.togglePlugin)
|
||||
|
||||
api.use('/plugin/:plugin', pluginController.routeAPI)
|
||||
|
||||
// OAUTH
|
||||
api.get('/clients', isAuth, oauthController.getClients)
|
||||
api.get('/client/:client_id', isAuth, oauthController.getClient)
|
||||
|
||||
Reference in New Issue
Block a user