-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (24 loc) · 1.11 KB
/
index.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
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');
const env = process.env.NODE_ENV || 'development';
mongoose.connect(env === 'development' ? config.DB_URI_DEV : config.DB_URI, {useUnifiedTopology: true, useNewUrlParser: true})
const app = express()
app.use(compression())
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'))
app.use('/mail', require('./routes/mailRouter'))
env !== 'development' && app.get('*', (req, res) => {
res.set('Cache-Control', 'public, max-age="31557600"') //onji varsha
res.header('Cache-Control', 'public, max-age="31557600"') //onji varsha
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
app.listen(process.env.PORT || 5000)