Add server plugin loader

This commit is contained in:
Cohee
2023-12-16 22:21:40 +02:00
parent b569d74552
commit 16795dd5cc
6 changed files with 179 additions and 3 deletions

View File

@ -93,9 +93,9 @@ const cliArguments = yargs(hideBin(process.argv))
}).parseSync();
// change all relative paths
const directory = process['pkg'] ? path.dirname(process.execPath) : __dirname;
const serverDirectory = process['pkg'] ? path.dirname(process.execPath) : __dirname;
console.log(process['pkg'] ? 'Running from binary' : 'Running from source');
process.chdir(directory);
process.chdir(serverDirectory);
const app = express();
app.use(compression());
@ -621,6 +621,8 @@ const setupTasks = async function () {
exitProcess();
});
await loadPlugins();
console.log('Launching...');
if (autorun) open(autorunUrl.toString());
@ -632,6 +634,16 @@ const setupTasks = async function () {
}
};
async function loadPlugins() {
try {
const pluginDirectory = path.join(serverDirectory, 'plugins');
const loader = require('./src/plugin-loader');
await loader.loadPlugins(app, pluginDirectory);
} catch {
console.log('Plugin loading failed.');
}
}
if (listen && !getConfigValue('whitelistMode', true) && !getConfigValue('basicAuthMode', false)) {
if (getConfigValue('securityOverride', false)) {
console.warn(color.red('Security has been overridden. If it\'s not a trusted network, change the settings.'));