-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
29 lines (22 loc) · 993 Bytes
/
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
const express = require('express')
const morgan = require('morgan')
const bodyParser = require('body-parser')
const mongoose = require('mongoose').set('debug', true);
const path = require('path');
require('dotenv').config();
require('./services/passport.js')
const compression = require('compression')
const config = require('./config.js');
const env = process.env.NODE_ENV || 'development';
mongoose.connect(env === 'development' ? config.DB_URI_DEV : process.env.MONGO_URI, {useUnifiedTopology: true, useNewUrlParser: true})
const app = express()
app.use(compression())
app.use(bodyParser.urlencoded({extended:true}))
env !== 'development' && app.use(express.static(path.join(__dirname, 'client/build')));
env === 'development' && app.use(morgan('dev'))
app.use(bodyParser.json())
app.use('/api', require('./routes/router'))
env !== 'development' && app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
app.listen(process.env.PORT || 5000)