-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (36 loc) · 1.05 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
require('dotenv').config()
const express = require('express')
const exphbs = require('express-handlebars')
const session = require('express-session')
const MongoDBStore = require('connect-mongodb-session')(session);
const { MONGODB_URI } = require('./config/connection')
const apiRoutes = require('./routes/apiRoutes')
const htmlRoutes = require('./routes/htmlRoutes')
const app = express();
app.use(session({ secret: 'somevalue' }));
const store = new MongoDBStore({
uri: MONGODB_URI,
collection: 'sessions'
});
// Catch errors
store.on('error', function(error) {
console.log(error);
});
/*app.use(session({
secret: process.env.SESSION_SECRET,
name: 'mongo-blog-session',
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7, // 1 week
},
store,
resave: true,
saveUninitialized: false
}));*/
app.engine('handlebars', exphbs.engine());
app.set('view engine', 'handlebars');
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(express.static('./public'))
app.use('/api', apiRoutes)
app.use('/', htmlRoutes)
module.exports = app