-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 983 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
32
33
34
35
36
37
38
39
40
41
const express =require('express');
const cors = require('cors')
const routerApi = require('./src/routes');
const {errorHandler,boomErrorHandler,ormErrorHandler} = require('./src/middlewares/error.handler');
const app = express();
const port =process.env.PORT || 3000;
//para enviar información en formato json
app.use(express.json());
//cors
const whiteList = ['http://localhost:8080','https://myFrontendApp.com'];
const options = {
origin: (origin,callback) => {
if(whiteList.includes(origin) || !origin){
callback(null,true)
}else{
callback(new Error('Cors error, user not allowed'))
}
}
}
app.use(cors(options));
//ejecutamos las estrategias
require('./src/utils/auth');
//llamamos la función del routes/index.js y le pasamos app
routerApi(app);
app.use(ormErrorHandler);
app.use(boomErrorHandler);
app.use(errorHandler);
app.get('/',(req,res) => {
res.send('hello root');
});
app.listen(port, () => {
console.log('port '+port);
});