-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (35 loc) · 1.24 KB
/
server.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
37
38
39
40
41
42
43
44
45
const dotenv = require('dotenv');
const express = require('express');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const connectDB = require('./config/db');
const SocketServer = require('./socketServer');
const {ExpressPeerServer} = require('peer');
const path = require('path');
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
io.on('connection', socket => {
SocketServer(socket);
});
ExpressPeerServer(http, {path: '/'});
app.use(express.json({limit: '50mb'}));
app.use(cors());
app.use(cookieParser());
app.use('/api', require('./routes/auth.route'));
app.use('/api', require('./routes/user.route'));
app.use('/api', require('./routes/post.route'));
app.use('/api', require('./routes/comment.route'));
app.use('/api', require('./routes/notification.route'));
app.use('/api', require('./routes/message.route'));
dotenv.config({
path: './config/.env'
});
connectDB();
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
})
}
http.listen(process.env.PORT, () => console.log(`Server is running on PORT ${process.env.PORT}`));