-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (28 loc) · 786 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
const express = require('express');
const cors = require('cors');
const routerApi = require('./routes');
const { logErrors, errorHandler, boomErrorHandler } = require('./middlewares/error.handler');
const app = express();
const port = 3000;
app.use(express.json());
const whiteList = ['http://localhost:8080','https://myapp.com'];
const options = {
origin: (origin, callback) => {
if(whiteList.includes(origin)) {
callback(null, true);
} else {
callback(new Error('Not allowed'));
}
}
};
app.use(cors(options));
app.get('/', (req, res) => {
res.send('Hola mi server en express');
});
routerApi(app);
app.use(logErrors);
app.use(boomErrorHandler);
app.use(errorHandler);
app.listen(port, () => {
console.log('Escuchando en el puerto ' + port);
});