-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (29 loc) · 1.03 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
const express = require('express');
const bodyParser = require('body-parser')
const route = require('./route/index')
const errorServer = require('./route/errorServer')
const errorNotFound = require('./route/errorNotFound')
const dbconnect = require('./configs/mongoose.connect')
const environement = require('./configs/environement')
//const server = require ('./configs/server.config')
const app = express();
dbconnect(()=>{
app.all('/*', (req, res, next)=> {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key,Authorization');
if (req.method == 'OPTIONS') {
res.status(200).end();
} else {
next();
}
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false }));
app.use('/',route);
app.use(errorNotFound);
app.use(errorServer)
app.listen(environement.port,() => {
console.log(`app listen in port ${environement.port}`)
})
})