diff --git a/src/plugin-loader.js b/src/plugin-loader.js index 3c4550492..92e566a51 100644 --- a/src/plugin-loader.js +++ b/src/plugin-loader.js @@ -5,6 +5,12 @@ const express = require('express'); const { getConfigValue } = require('./util'); const enableServerPlugins = getConfigValue('enableServerPlugins', false); +/** + * Map of loaded plugins. + * @type {Map} + */ +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);