-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (30 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// index.js
const express = require('express');
const bodyParser = require('body-parser');
const http = require('http');
const socketIO = require('socket.io');
const chatRoutes = require('./src/routes/chatRoutes');
const socketHandler = require('./src/handlers/socketHandler');
const { consume } = require('./src/kafka/consumer');
const { startServer, handleShutdown } = require('./src/handlers/serverHandler');
const app = express();
const server = http.createServer(app);
const io = socketIO(server);
const PORT = process.env.PORT || 3000;
// Middleware
app.use(bodyParser.json());
app.use('/api', chatRoutes);
app.use(express.static('public'));
// Use the socketHandler
socketHandler(io);
// Initialize kafka consumer
consume(io).then(r => {
console.log("------------Working consumer, waiting for server to start-----------")
}).catch(err => {
console.log("Occurred error ", err)
});
// Synchronize Sequelize models with the database
(async () => {
const srv = await startServer(PORT, server);
await handleShutdown(srv);
})();