forked from LucasNatoli/accounts-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 933 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
const express = require('express')
const bodyParser = require('body-parser')
const models = require('./models')
const router = require('./router')
const app = express()
const env = process.env;
const PORT = env.USRACCNT_PORT;
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// Add CORS headers
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Method');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
res.header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');
next();
});
router(app, models)
//drop and resync with { force: true }
models.sequelize.sync().then(() => {
console.log('models sync ok')
app.listen(PORT, () => {
console.log('APP listening on port:', PORT)
})
})