-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
55 lines (43 loc) · 1.4 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
46
47
48
49
50
51
52
53
54
55
const express = require('express');
const bodyParser = require('body-parser');
const passport = require('passport');
const mongoose = require('mongoose');
const compression = require('compression');
const cors = require('cors');
const path = require('path');
const crons = require('./config/crons');
const comments = require("./Comments/comments");
require('dotenv').config();
const app = express();
app.use(compression());
require('./config/passport')(passport);
mongoose
.connect(
process.env.MONGO_URI, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
useCreateIndex: true
},
)
.then(() => console.log('MongoDB Connected'))
.catch((err) => console.log(err));
app.use(cors());
app.use('/public', express.static('client'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.json({ type: "text/*" }));
if(process.env.NODE_ENV === 'production'){
app.use(express.static('client/build'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}
app.use('/api/users', require('./routes/users'));
app.use('/api/course', require('./routes/course'));
app.use('/api/comment', require('./routes/comment'));
const PORT = process.env.PORT || 5000;
const server = app.listen(PORT, () => {
console.log(`Server is running on ${PORT} ...`);
});
comments.setupSocket(server);