feat(web): serve the dashboard and its interface

The front-end is plain JavaScript served as is: no build step to run before
the bot starts, and no second toolchain to keep alive. A simple/advanced
switch hides the technical panels without ever standing in for a permission.

`npm run setup` starts the wizard alone, because the bot refuses to boot
without a token and the `.env` has to be writable from somewhere. When the
webhook and the dashboard share a port, a single HTTP server is started.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-23 20:09:14 +02:00
1 parent bf92badb05
commit 06a9be0cba
23 files changed
+5850 -2

No files matched your search

+11 -2
View File
@@ -4,9 +4,15 @@ import { loadCommands } from './core/command-loader.js';
import { registerEvents } from './core/event-loader.js';
import { logger } from './core/logger.js';
import { closeDatabase, initDatabase } from './database/index.js';
import { startWebServer, webhookSharesWebPort } from './web/server.js';
import { startWebhookServer } from './webhooks/server.js';
assertRequiredEnv(['DISCORD_TOKEN', 'DISCORD_CLIENT_ID', 'DISCORD_GUILD_ID']);
try {
assertRequiredEnv(['DISCORD_TOKEN', 'DISCORD_CLIENT_ID', 'DISCORD_GUILD_ID']);
} catch (error) {
logger.error(`${error.message}. Lance \`npm run setup\` pour remplir le .env pas à pas.`);
throw error;
}
initDatabase();
@@ -17,7 +23,9 @@ for (const command of await loadCommands()) {
}
await registerEvents(client);
const webhookServer = env.webhook.enabled ? startWebhookServer(client) : null;
// When both listen on the same port, the dashboard serves the webhook route too.
const webServer = env.web.enabled ? startWebServer({ client }) : null;
const webhookServer = env.webhook.enabled && !webhookSharesWebPort() ? startWebhookServer(client) : null;
process.on('unhandledRejection', (reason) => logger.error('Unhandled promise rejection', reason));
process.on('uncaughtException', (error) => logger.error('Uncaught exception', error));
@@ -25,6 +33,7 @@ process.on('uncaughtException', (error) => logger.error('Uncaught exception', er
async function shutdown(signal) {
logger.info(`Received ${signal}, shutting down`);
webhookServer?.close();
webServer?.close();
await client.destroy();
closeDatabase();
process.exit(0);