-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (24 loc) · 809 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
const express = require('express')
// create express server instance
const app = express()
const bodyParser = require('body-parser')
const httpLogger = require('./helpers/middleware')
const { handleError } = require('./helpers/error')
const routes = require('./Routes')
// use winston based logger to show info about the app
app.use(httpLogger)
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
// add default headers to all requests
app.use((req, res, next) => {
res.append('Access-Control-Allow-Origin', ['*'])
res.append('Access-Control-Allow-Headers', 'Content-Type')
next()
})
// add application routes
app.use('/api', routes)
// use custom error handler to create error objects
app.use((err, req, res, next) => {
handleError(err, res)
})
module.exports = app