-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (46 loc) · 1.36 KB
/
app.js
File metadata and controls
59 lines (46 loc) · 1.36 KB
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
// libraries
const express = require('express');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const session = require('express-session')
const flash = require('connect-flash')
const passport = require('passport')
require('./middleware/passport').validate(passport)
// middlewares/
const errorHandling = require('./middleware/error_handling');
// const auth = require('./middlewares/auth');
// router
const router = require('./router/index_router');
// app creation
const app = express();
// using libraries
// app.use(fileUpload({ createParentPath : true }));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(session({
secret : 'secret',
resave : true,
saveUninitialized : true
}))
//passport
app.use(passport.initialize())
app.use(passport.session())
app.use(flash())
app.use((req, res, next) => {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
next();
})
app.use(cookieParser());
app.use(morgan('tiny'));
// setting ejs to be view engine
app.set('view engine', 'ejs');
// allow public directory
app.use(express.static('public'))
// using router
app.use('/', router);
// using error handling middleware
app.use(errorHandling.notFound);
app.use(errorHandling.errorHandler);
module.exports = app;