-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·45 lines (34 loc) · 1.02 KB
/
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
37
38
39
40
41
42
43
44
45
'use strict'
require('app-module-path').addPath(__dirname)
const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const config = require('api/config')
const authMiddleware = require('api/middlewares/auth')
const errorMiddleware = require('api/middlewares/error')
const app = express()
app.use(cors({
origin: config.server.allowOrigins,
credentials: true,
}))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true,
}))
//static content
app.use(express.static(path.join(__dirname, 'client')))
app.use(express.static(path.join(__dirname, 'public')))
//auth middleware
app.use(authMiddleware)
//controllers
app.use(`/api/${config.version}`, require('api/controllers'))
//error middleware
app.use(errorMiddleware)
app.listen(config.server.port, () => {
console.log('API is ready.')
})
process.on('uncaughtException', (reason, p) => {
console.error('Uncaught Exception at: Promise', p, 'Reason:', reason)
})
module.exports = app