-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (37 loc) · 1.19 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
57
58
const express = require('express');
const cors = require('cors');
const app = express();
const path = require('path');
const body = require('body-parser')
const multer = require('multer')
const upload = multer({
dest:'images'
})
const mongooseConnect = require('./db/database')
const productRoute = require('./routes/product')
const userRoute = require('./routes/user')
const authRouth = require('./routes/auth')
app.use(body.urlencoded({extended:true}))
app.use(body.json())
app.use(cors());
// app.use((req,res,next) =>{
// console.log('method',req.method,'path',req.path);
// next()
// })
app.use(authRouth)
app.use('/product',productRoute)
app.use('/user',userRoute)
mongooseConnect.mongoConnect()
const port = 8000;
if (process.env.NODE_ENV === 'production') {
// Exprees will serve up production assets
app.use(express.static('client/build'));
// Express serve up index.html file if it doesn't recognize route
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
app.listen(process.env.PORT || port , () =>{
console.log(`Server started on port ${port}`)
});