-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (41 loc) · 1.26 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
const express = require('express');
const mongoose = require('mongoose');
const authRoutes = require('./routes/auth-routes');
const profileRoutes = require('./routes/profile-routes');
const passportSetup = require('./config/passport-setup');
const keys = require('./config/keys');
const cookieSession = require('cookie-session');
const passport = require('passport');
const app = express();
// set up view engine
app.set('view engine', 'ejs');
// set up static directory
app.use(express.static(__dirname + '/public'));
// set up session cookies
app.use(
cookieSession({
maxAge: 24 * 60 * 60 * 1000, // this cookie is valid for one day
keys: [keys.session.cookieKey], // encrypt cookie before send to the browser
})
);
// init passport
app.use(passport.initialize());
app.use(passport.session());
// set up routes
app.use('/auth', authRoutes);
app.use('/profile', profileRoutes);
// create home route
app.get('/', (req, res) => {
res.render('home', { user: req.user });
});
// connect with db and run the server
const PORT = process.env.PORT || 3000;
mongoose.connect(
keys.mongodb.dbURI,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => {
app.listen(PORT, () => {
console.log(`app now listening for requests on port ${PORT}`);
});
}
);