-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (38 loc) · 1.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
// Passport config
import methodOverride from 'method-override'
import session from 'express-session'
import passport from 'passport'
import initialize from './utils/passport-config.js'
initialize()
// Routes
import index from './routes/index.js'
import register from './routes/register.js'
import login from './routes/login.js'
import todos from './routes/todos.js'
import incorrectCredentials from './routes/incorrect-credentials.js'
import logout from './routes/logout.js'
import express from 'express'
const app = express()
app.set('view-engine', 'ejs')
app.use(express.static('public'))
app.use(express.urlencoded({ extended: false }))
// Passport
app.use(session({
secret: process.env.SESSION_KEY,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(methodOverride('_method')) // logout
// Routes
app.use('/', index)
app.use('/register', register)
app.use('/login', login)
app.use('/todos', todos)
app.use('/incorrect-credentials', incorrectCredentials)
app.delete('/logout', logout)
app.use('/error', (req, res) => {
res.render('error.ejs', { error: 'This shit cannot be add up' })
})
app.listen(3000, () => console.log(`Server listening on port 3000`))