import { buildServer } from './app.js'; import { loadConfig } from './config.js'; import { DiscordSource } from './discord-source.js'; const cfg = loadConfig(); // 겜녹이 봇은 이 서버만 디스코드에 연결한다 (봇 토큰은 앱에 보내지 않는다). BOT_GATEWAY=0 이면 끈다 let log: { info: (o: any, m?: string) => void; error: (o: any, m?: string) => void } = { info: () => undefined, error: (o, m) => console.error(m, o) }; const botSource = process.env.BOT_GATEWAY === '0' ? undefined : new DiscordSource({ info: (o, m) => log.info(o, m), error: (o, m) => log.error(o, m) }); const { app } = await buildServer(cfg, { botSource }); log = app.log.child({ area: 'discord' }); await app.listen({ host: cfg.host, port: cfg.port }); if (botSource) { // 디스코드에 못 붙어도 사이트는 계속 돈다 (discord.js 가 알아서 다시 연결) botSource.login(cfg.botToken).catch((e) => app.log.error(e, '겜녹이 봇 디스코드 연결 실패')); } const stop = async () => { await app.close(); await botSource?.destroy(); process.exit(0); }; process.on('SIGTERM', stop); process.on('SIGINT', stop);