-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (24 loc) · 899 Bytes
/
app.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
require('./db/mongoose');
const express = require('express');
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');
const keys = require('./config/keys');
const app = express();
const {usersRoutes,quizzesRoutes, statsRoutes} = require('./routes')
app.use(bodyParser.json());
app.use(cookieSession({
maxAge: 60000 * 24,
keys: [keys.cookieSecret]
}));
app.use('/api', usersRoutes, quizzesRoutes, statsRoutes);
const PORT = process.env.PORT || 5000;
if(process.env.NODE_ENV === 'production'){
// Express will serve Production Assets
app.use(express.static('client/build'));
//Express will serve up the index.html
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
});
}
app.listen(PORT,()=> console.log(`App started on port ${PORT}!`));