-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (33 loc) · 1.01 KB
/
server.js
File metadata and controls
47 lines (33 loc) · 1.01 KB
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
37
38
39
40
41
42
43
44
45
import express from 'express';
import { Server } from 'socket.io';
import { socketCtrl } from './controllers/socket.js';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import userRouter from './routes/user.js';
import MessageRoutes from './routes/messages.js';
import RoomRoutes from './routes/room.js';
import dbConnect from './utils/dbConnect.js';
import cors from 'cors';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const PORT = process.env.PORT || 8080;
const server = app.listen(PORT, () => {
dbConnect();
console.log(`Server is running on http://localhost:${PORT}`);
});
const io = new Server(server, {
pingTimeout: 60000,
cors: {
origin: '*',
},
});
socketCtrl(io);
app.use(express.json());
app.use(cors());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.use('/api/v1/users', userRouter);
app.use('/api/v1/messages', MessageRoutes);
app.use('/api/v1/rooms', RoomRoutes);