-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 949 Bytes
/
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
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const passport = require('./config/auth')
const https = require('https')
const { users, sessions, items, userdocs, themes, admins } = require('./routes')
const port = process.env.PORT || 3030
const app = express()
const server = https.Server(app)
app
.use(cors())
.use(bodyParser.urlencoded({ extended: true }))
.use(bodyParser.json())
.use(passport.initialize())
.use(users)
.use(sessions)
.use(items)
.use(userdocs)
.use(themes)
.use(admins)
.use((req, res, next) => {
const err = new Error('Not Found')
err.status = 404
next(err)
})
.use((err, req, res, next) => {
res.status(err.status || 500)
res.send({
message: err.message,
error: app.get('env') === 'development' ? err : {}
})
})
.listen(port, () => {
console.log(`Server is listening on port ${port}`)
})