-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (35 loc) · 859 Bytes
/
Copy pathindex.js
File metadata and controls
44 lines (35 loc) · 859 Bytes
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
42
43
44
const express = require('express');
const cors = require('cors');
const routerApi = require('./routes');
const {
logErrors,
errorHandler,
boomErrorHandler,
} = require('./middleware/error.handler');
const app = express();
const port = 3000;
const whiteList = ['http://localhost:80808', 'https://luishron.com'];
const options = {
origin: (origin, callBack) => {
if (whiteList.includes) {
callBack(null, true);
} else {
callBack(new Error('no permitio'));
}
},
};
app.use(cors(options));
app.use(express.json());
app.get('/', (req, res) => {
res.send('Hola mi server en express');
});
app.get('/nueva-ruta', (req, res) => {
res.send('Hola, soy una nueva ruta');
});
routerApi(app);
app.use(logErrors);
app.use(boomErrorHandler);
app.use(errorHandler);
app.listen(port, () => {
console.log('Mi port' + port);
});