-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (42 loc) · 1.4 KB
/
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
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
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const path = require("path");
const keys = require("./app/config/keys");
const cookieSession = require("cookie-session");
const passport = require("passport");
const bodyParser = require('body-parser');
require('./app/models/User'); //should come before passport
require('./app/models/Survey');
require('./app/services/passport');
mongoose.connect(keys.mongoose.uri);
/*
app.use is for declaring middleware which pre-process incoming requests before hitting routes
*/
//Enabling Cookies
app.use(
cookieSession({
maxAge : 30*24*60*60,
keys : [keys.cookieSession.key]
})
);
//Asking passport to use cookies
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());
require('./app/routes/authentication')(app);
require('./app/routes/billing')(app);
require('./app/routes/survey')(app);
app.set('public', path.join(__dirname, 'public'));
//Set Static Path
app.use('/public', express.static(__dirname + '/public'));
if(process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
console.log("dirname :" +__dirname);
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}
app.listen(process.env.PORT || 8003, function () {
console.log("Server serving on 8003...");
});