-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (90 loc) · 2.56 KB
/
index.js
File metadata and controls
108 lines (90 loc) · 2.56 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const path = require('path');
const express = require('express');
const mongoose = require('mongoose');
const cookieSession = require('cookie-session');
const session = require('express-session');
const expressValidator = require('express-validator');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const passport = require('passport');
const keys = require('./config/keys');
// git push heroku master
// git push origin master
// Services
require('./services/passport');
mongoose.connect(keys.mongoURI).then(() => {
console.log(`*** Database Connected ***`)
}, err => {
console.log('Unable connect to database: ', err);
});
const app = express();
// app.set('views', path.join(__dirname, 'views'));
// app.engine('html', require('hbs').__express);
// app.set('view engine', 'hbs');
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));
// app.use(cookieParser());
// app.use(express.static(path.join(__dirname, 'public')));
// cookie-session
app.use(
cookieSession({
name: 'authSession',
maxAge: 300 * 24 * 60 * 60 * 1000, // month
keys: [keys.cookieKey]
})
);
// express-session
// app.use(session({
// secret: keys.cookieKey,
// saveUninitialized: true,
// resave: false,
// // cookie: { secure: true }
// }))
app.use(expressValidator({
errorFormatter: (param, msg, value) => {
let namespace = param.split('.'),
root = namespace.shift(),
formParam = root
while (namespace.length) {
formParam += `[${namespace.shift()}]`
}
return {
param: formParam,
msg: msg,
value: value
}
}
}));
app.use(passport.initialize());
app.use(passport.session());
// Simple middleware
// app.use((req, res, next) => {
//
// next()
// });
// Pages
// require('./routes/pagesRoutes')(app);
// Auth
require('./routes/authRoutes')(app);
// Emails
require('./routes/formRoutes')(app);
// Debug
require('./routes/debugAndSessionRoutes')(app);
// Payments
require('./routes/paymentRoutes')(app);
if (process.env.NODE_ENV === 'production') {
// Express will serve up production assets
// like our main.js file, or main.css file!
app.use(express.static('client/build'));
// Express will serve up the index.html file
// if it doesn't recognize the route
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
const port = process.env.PORT || 8080;
app.listen(port, () => {
// http://localhost:8080/
// https://quiet-basin-37027.herokuapp.com/
console.log(`Starting: http://localhost:${port}`);
});