-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (56 loc) · 1.85 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
58
59
60
61
62
63
64
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const uri = MONGO_DB_URI;
const auth = require('./routes/auth');
const passport = require('passport');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const index = require('./routes/index');
const bodyparser = require('body-parser');
const exphbs = require('express-handlebars');
const Handlebars = require('handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');
const stories = require('./routes/stories');
const methodOverride = require('method-override');
const { truncate, stripTags, formatDate, select,editIcon } = require('./helper/hbs');
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }, () => {
console.log("connected to DB");
});
const app = express();
app.engine('handlebars', exphbs({
helpers: {
truncate: truncate,
stripTags: stripTags,
formatDate: formatDate,
select: select,
editIcon: editIcon
},
defaultLayout: 'main',
handlebars: allowInsecurePrototypeAccess(Handlebars)
}));
app.set('view engine', 'handlebars');
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json());
app.use(methodOverride('_method'));
app.use(cookieParser());
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use((req, res, next) => {
res.locals.user = req.user || null;
next();
});
require('./config/passport')(passport);
app.use('/auth', auth);
app.use('/', index);
app.use('/stories', stories);
app.use(express.static(path.join(__dirname, './public')));
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});