-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (61 loc) · 1.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const express = require('express');
const jwt = require('jsonwebtoken');
const axios = require("axios");
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
const expressValidator = require('express-validator');
const flash = require('connect-flash');
const session = require('express-session');
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const cors = require('cors')
const routes = require('./routes/index');
const users = require('./routes/users');
// Init app
const app = express();
// Routes Init
//const routes = require('./routes/user');
//app.use('/api', routes);
//Enable Cors
app.use(cors())
// View Engine
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', exphbs({ defaultLayout: 'layout' }));
app.set('view engine', 'handlebars');
//Bodyparser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// Set Static folder
app.use(express.static(path.join(__dirname, 'public')));
// Express Session
app.use(session({
'secret': 'secret',
saveUninitialized: true,
resave: true
}))
// Passport Init
app.use(passport.initialize());
app.use(passport.session());
// express validator
app.use(expressValidator());
// Connect Flash
app.use(flash());
// Global Variable 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.get('/api', (req, res) => {
// axios.get("http://localhost:3000/users").then((result) => {
// res.json(result.data)
// })
// })
app.use('/', routes);
app.use('/users', users);
app.set('port', (process.env.PORT || 5000))
app.listen(app.get('port'), () => console.log(`app listen on port ${app.get('port')}`))