-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (47 loc) · 1.49 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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// express related
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cookieSession = require('cookie-session');
const passport = require('passport');
// models
require('./models/User');
require('./models/Survey');
// services
require('./services/passport');
// user created
const keys = require('./config/keys');
console.log('mongo uri key --- ', keys.mongoURI);
mongoose.connect(keys.mongoURI);
console.log('cookie key --- ', [keys.cookieKey]);
const app = express();
console.log('started expressJS ... ');
app.use(bodyParser.json());
app.use(cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [keys.cookieKey]
}));
app.use(passport.initialize());
app.use(passport.session());
console.log('added passportJS ... ');
// Routes
// need app present beforehand
require('./routes/authRoutes')(app);
require('./routes/billingRoutes')(app);
require('./routes/surveyRoutes')(app);
if(process.env.NODE_ENV === 'production'){
app.use(express.static('client/build'));
// Express serves production assets like main.js or main.css file.
// Express will serve indexhtml if it doesnt see ruote
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
app.get('/', (req, resp) => {
resp.write("wee");
console.log('default route');
});
console.log('starting app ... ');
const PORT = process.env.PORT || 5000;
app.listen(PORT);