-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (46 loc) · 1.42 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 session = require('express-session')
const MongoStore = require('connect-mongo');
const flash = require('connect-flash');
var methodOverride = require('method-override')
const pageRoutes = require('./routes/pageRoutes')
const courseRoutes = require('./routes/courseRoute')
const categoryRoutes = require('./routes/categoryRoutes')
const authRoutes = require('./routes/authRoute')
const Course = require('./models/Course')
const app = express();
app.set('view engine', 'ejs');
// Gloabal Variables
global.userIN = null;
// MİDDLEWARES
app.use(express.static('public'));
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.use(session({
secret: 'my_keyboard_cat',
resave: false,
saveUninitialized: true,
store: MongoStore.create({ mongoUrl: 'mongodb://127.0.0.1:27017/SmartEdu-db'})
}))
app.use('*',(req,res,next)=>{
userIN = req.session.userID
next();
})
app.use(flash());
app.use((req, res, next)=> {
res.locals.flashMessages = req.flash();
next();
})
app.use(
methodOverride('_method',{
methods:["GET","POST"]
})
)
app.use('/',pageRoutes)
app.use('/courses',courseRoutes)
app.use('/categories',categoryRoutes)
app.use('/users',authRoutes)
const port = 3000;
app.listen(port, () => {
console.log(`Our Port is ${port}`);
});