-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (41 loc) · 1.41 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
const express = require('express');
const app = express();
const session = require('express-session');
const flash = require('express-flash');
const connectDB = require('./config/db');
const MongoStore = require('connect-mongo');
const passport = require('passport');
const methodOverride = require('method-override')
const homeRoutes = require('./routes/home');
const expenseRoutes = require('./routes/expenses');
const trackerRoutes = require('./routes/tracker');
const accountRoutes = require('./routes/accounts');
// Settings and whatnot
app.set('view engine', 'ejs');
app.use(express.static('public'))
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(flash());
app.use(methodOverride('_method'));
// Connect DB
connectDB();
// THE ORDER OF THIS IS REALLY IMPORTANT -- session must come BEFORE passport setup stuff
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true,
store: MongoStore.create({ mongoUrl: process.env.DB_STRING })
}));
// Set up passport
require('./config/passport')(passport)
app.use(passport.initialize());
app.use(passport.session());
// Routes come last before starting server
app.use('/', homeRoutes);
app.use('/expenses', expenseRoutes);
app.use('/accounts', accountRoutes);
app.use('/tracker', trackerRoutes);
// Start Server
app.listen(process.env.PORT, () => {
console.log('Your server is running, you better go catch it!');
})