-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
36 lines (27 loc) · 905 Bytes
/
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
const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')
const cookieSession = require('cookie-session')
const routes = require('./routes/')
const app = express()
const PORT = process.env.PORT || 3000
const createId = () => '_' + Math.random().toString(36).substr(2, 9)
app.use(express.static(path.join(__dirname, 'public')))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cookieSession({
name: 'LoginCookieSession',
keys: [createId(), createId()],
maxAge: 24 * 60 * 60 * 1000
}))
app.use((req, res, next) => {
req.session.login = req.session.login || ''
req.session.tasks = req.session.tasks || []
req.session.completed = req.session.completed || []
next()
})
app.set('view engine', 'pug')
app.locals.pretty = true
app.use(routes)
app.listen(PORT)
console.log(`Listening on PORT ${PORT}...`)