-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (36 loc) · 1.14 KB
/
index.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
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors')
const bodyParser = require('body-parser')
const logger = require('morgan')
const favicon = require('serve-favicon');
const session = require('express-session')
const PORT = process.env.PORT || 3000
const DBPORT = process.env.MONGODB_URI
const SESSIONSECRET = process.env.SESSIONSECRET
let app = express()
mongoose.connect(DBPORT, { useNewUrlParser: true })
mongoose.Promise = global.Promise
let db = mongoose.connection
db.on('error', console.error.bind(console, 'MongoDB connection error:'))
app.use(logger('dev'))
app.use(cors())
app.use(
bodyParser.urlencoded({
extended: false
})
)
app.use(bodyParser.json())
app.use(session({ secret: SESSIONSECRET, resave: true, saveUninitialized: true, cookie: { maxAge: 24 * 60 * 60 * 1000 } }))
app.use(express.static('public'))
app.use(express.static('build'))
app.set('view engine', 'pug')
app.set('views', './views')
app.use(favicon('./public/favicon.ico'));
app.use('/', require('./routes'))
app.listen(PORT, err => {
if (err) {
throw err
}
console.info('Listening on port ' + PORT + '...')
})