-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 914 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
43
44
const express = require('express')
const debug = require('debug')('app:server')
const helmet = require('helmet')
const cors = require('cors')
const app = express()
const { config } = require('./config/index')
const authApi = require('./routes/auth')
const moviesApi = require('./routes/movies')
const userMoviesApi = require('./routes/userMovies')
const {
logErrors,
wrapErrors,
errorHandler
} = require('./utils/middleware/errorHandlers')
const notFoundHandler = require('./utils/middleware/notFoundHandler')
// helmet
app.use(helmet())
// cors
app.use(cors())
app.options('*', cors())
// body-parser
app.use(express.json())
// routes
authApi(app)
moviesApi(app)
userMoviesApi(app)
// catch 404
app.use(notFoundHandler)
// errors middleware
app.use(logErrors)
app.use(wrapErrors)
app.use(errorHandler)
app.listen(config.port, () => {
debug(`App linstening on http://localhost:${config.port}`)
})