generated from ekassos/to-do-app-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (49 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
58
59
const express = require('express');
const app = express();
const exphbs = require('express-handlebars');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const passport = require('passport');
const flash = require('connect-flash');
const { connectMongoDb } = require('./mongodb')
const settings = require('./controllers/settings')
const PORT = process.env.PORT || settings.port
const users = require('./router/users')
const todos = require('./router/todo')
connectMongoDb()
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
})
);
app.use(express.urlencoded({ extended: true }));
app.use(express.json())
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
require('./controllers/config')(passport);
app.use(flash());
// What content files to use
app.engine('hbs', exphbs({extname: '.hbs'}));
app.set('view engine', 'hbs');
// main details for redirect
app.get('/', (req, res) => {
let title = 'To-Do App'
res.render('index', {
title: title
})
})
app.get('/about', (req, res) => {
res.render('about')
})
app.use(function(req, res, next) {
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next();
})
app.use('/users', users)
app.use('/todo', todos)
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`)
})