-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
56 lines (35 loc) · 1.16 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
56
const express = require('express');
const connectDB = require('./db')
const users = require('./api/users')
const bodyParser = require('body-parser')
const cors = require('cors')
const posts = require('./api/posts')
const http = require("http");
const app = express();
const path = require('path')
const passport = require('passport')
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
connectDB()
const PORT = process.env.PORT || 5000;
const server = app.listen(PORT, () => console.log(`Server running on port ${PORT}`))
const socketio = require('socket.io')
const io = socketio(server)
app.use(passport.initialize())
require('./config/passport')(passport)
const questions = require('./api/questions')(io)
app.use('/api/users', users)
app.use('/api/posts', posts)
app.use('/api/questions', questions)
if(process.env.NODE_ENV==='production'){
app.use(express.static(`${__dirname}/client/build`))
app.get('*', (req, res) => {
res.sendFile('/client/build/index.html', { root: __dirname }, (err) => {
if (err) {
res.status(err.status).end();
}
});
}
)
}