-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (41 loc) · 1.29 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
const express = require('express')
const hbs = require('express-hbs')
const path = require('path')
const session = require('express-session')
const passport = require('./passport')
const app = express()
app.engine('hbs', hbs.express4({
defaultLayout: path.join(__dirname, 'views/layouts/default'),
partialsDir: path.join(__dirname, 'views/partial'),
layoutsDir: path.join(__dirname, 'views/layouts')
}))
app.set('view engine', 'hbs')
app.set('views', path.join(__dirname, 'views/pages'))
app.use('/', express.static(path.join(__dirname, 'public')))
app.use(session({
secret: 'lsdgdkhfbdkgbdk',
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use('/login', require('./routes/login'))
app.use('/products', require('./routes/products'))
app.use('/categories', require('./routes/categories'))
app.get('/logout', (req, res) => {
req.user = null
req.logOut()
req.session.destroy((err) => {
res.redirect('/')
})
})
app.get('/', (req, res) => {
// if (!req.user) {
// return res.redirect('/login')
// }
return res.redirect('/categories')
})
app.listen(2626, () =>
console.log("Server started on http://localhost:2626"))