Dev (#12)
* health check * Update Dockerfile * simplifying the deployment * Update Bot.js makes the find team command public * test (#9) * Dev (#7) * health check * Update Dockerfile * simplifying the deployment * Dev (#8) * health check * Update Dockerfile * simplifying the deployment * Update Bot.js makes the find team command public * Update PlayerService.js * massive update???? could break stuff * Update Bot.js update
This commit is contained in:
31
index.js
31
index.js
@@ -3,6 +3,13 @@ const { createClient } = require('@supabase/supabase-js');
|
||||
const Bot = require('./src/Bot');
|
||||
require('dotenv').config();
|
||||
|
||||
// Import Express and create an app for health checks and webhooks
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
// Middleware for parsing JSON
|
||||
app.use(express.json());
|
||||
|
||||
// Initialize logger
|
||||
const logger = winston.createLogger({
|
||||
level: 'debug',
|
||||
@@ -26,8 +33,30 @@ const supabase = createClient(
|
||||
process.env.SUPABASE_KEY
|
||||
);
|
||||
|
||||
// Initialize and start bot
|
||||
// Initialize bot
|
||||
const bot = new Bot(process.env.DISCORD_TOKEN, supabase, logger);
|
||||
|
||||
// Add health check endpoint
|
||||
app.get('/health', (req, res) => {
|
||||
res.status(200).json({ status: 'healthy' });
|
||||
});
|
||||
|
||||
// Add notification webhook endpoint (this will be used by the NotificationService)
|
||||
app.post('/api/match-notification', async (req, res) => {
|
||||
if (bot.notificationService && bot.notificationService.handleMatchNotification) {
|
||||
await bot.notificationService.handleMatchNotification(req, res);
|
||||
} else {
|
||||
res.status(503).json({ error: 'Notification service not ready' });
|
||||
}
|
||||
});
|
||||
|
||||
// Start the server
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
logger.info(`Health check server listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
// Initialize and start bot
|
||||
bot.start().catch(error => {
|
||||
console.error('Failed to start bot:', error);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user