-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (29 loc) · 915 Bytes
/
server.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
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const morgan = require('morgan')
const populateDB = require('./app/utils/populate-db')
const compression = require('compression')
global.appState = {}
app.use(morgan('dev'))
app.use(compression())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
next();
}
});
app.use('/api', require('./app/routes/default'))
if (require('./settings.json').seedDb) {
populateDB()
}
module.exports = app
console.log('API Started')