-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
33 lines (27 loc) · 917 Bytes
/
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
require('dotenv').config({ path: '.env' });
const db = require('./database/models');
db.onlineUsers = {};
const Koa = require('koa');
const app = new Koa();
const server = require('http').Server(app.callback());
const cors = require('@koa/cors');
const bodyParser = require('koa-bodyparser');
const router = require('./router');
const io = require('socket.io')(server, {
pingInterval: 900000,
pingTimeout: 5000,
});
const Socketer = require('./socket');
const ioClient = new Socketer(io, db);
io.on('connection', (socket) => ioClient.connection(socket));
app.use(bodyParser());
app.use(cors());
app.use(router.routes());
(async () => {
// await db.sequelize.drop(); // drop db and
// await db.sequelize.sync({ force: true }); // restart it
await db.sequelize.sync();
server.listen(process.env.PORT, async () => {
console.log(`Listening on port ${process.env.PORT}`);
});
})()