-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
77 lines (58 loc) · 2.21 KB
/
server.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
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
const mongooseSetup = require('./models/mongooseSetup')
const passport = require('passport')
const initializePassport = require('./passport-config')
const flash = require('express-flash')
const session = require('express-session')
const bodyParser = require('body-parser')
//Models
const userModel = require('./models/userModel')
//Routes
const loginRoute = require('./routers/loginRoute')
const adminRoute = require('./routers/adminRoute')
const indexRoute = require('./routers/indexRoute')
const registerRoute = require('./routers/registerRoute')
const apiRoute = require('./routers/apiRoute')
const logoutRoute = require('./routers/logoutRoute.js')
const productRoute = require('./routers/productRoute.js')
const categoryRoute = require('./routers/categoryRoute.js')
//veritabani sistemini init ediyoruz
mongooseSetup.init()
initializePassport(passport)
app.set('view-engine', 'ejs')
app.use(express.static('./public'))
app.use(bodyParser.urlencoded({ extended: false }))
//site icerisinde get motedunun req degiskenine birsey eklemek icin flash yukluyoruz
app.use(flash())
//sunucunun Ram'ine session(cookie) atamak icin kullaniyoruz
app.use(session({
//RAM'e ekledikten sonra sifrelemek icin ne kadar uzun o kadar guvenli
secret:'Wmwy6eU8RW6cWwPnQx0d7YSGZtq0cVYIfy4nTivLeTZNfWJN35FUT3UDAKTpKW1z',//process.env.SESSION_SECRET,
//ardi ardina ayni kayit istegi gelirse kaydetme
resave:false,
//degisiklik yapilmamisi kaydetme
saveUninitialized:false,
//session'in omrunu milisaniye cinsinden belirtiyoruz
cookie:{maxAge:18000000}//5 hour in miliseconds
}))
//sifre giris sistemini init ediyoruz
app.use(passport.initialize())
//sifre giris sistemine session yetkisi veriyoruz
app.use(passport.session())
//Routes
app.use('/login', loginRoute)
app.use('/admin',adminRoute)
app.use('/', indexRoute)
app.use('/register', registerRoute)
app.use('/api',apiRoute)
app.use('/logout',logoutRoute)
app.use('/product',productRoute)
app.use('/category',categoryRoute)
app.all('*',(req,res,next) => {
res.status(404).redirect('/');
});
app.listen(port,(req,res)=>{
console.log('Listening on port:' + port)
})