Add check for server plugin id clash
This commit is contained in:
parent
73548faa33
commit
88993bd3e8
|
@ -5,6 +5,12 @@ const express = require('express');
|
|||
const { getConfigValue } = require('./util');
|
||||
const enableServerPlugins = getConfigValue('enableServerPlugins', false);
|
||||
|
||||
/**
|
||||
* Map of loaded plugins.
|
||||
* @type {Map<string, any>}
|
||||
*/
|
||||
const loadedPlugins = new Map();
|
||||
|
||||
/**
|
||||
* Determine if a file is a CommonJS module.
|
||||
* @param {string} file Path to file
|
||||
|
@ -186,11 +192,18 @@ async function initPlugin(app, plugin, exitHooks) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (loadedPlugins.has(id)) {
|
||||
console.error(`Failed to load plugin module; plugin ID '${id}' is already in use`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow the plugin to register API routes under /api/plugins/[plugin ID] via a router
|
||||
const router = express.Router();
|
||||
|
||||
await plugin.init(router);
|
||||
|
||||
loadedPlugins.set(id, plugin);
|
||||
|
||||
// Add API routes to the app if the plugin registered any
|
||||
if (router.stack.length > 0) {
|
||||
app.use(`/api/plugins/${id}`, router);
|
||||
|
|
Loading…
Reference in New Issue