-
Notifications
You must be signed in to change notification settings - Fork 135
/
index.js
41 lines (31 loc) · 888 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('./routes');
const { logErrors, errorHandler, boomErrorHandler } = require('./middlewares/error.handler');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
const whitelist = ['http://localhost:8080', 'https://myapp.co'];
const options = {
origin: (origin, callback) => {
if (whitelist.includes(origin) || !origin) {
callback(null, true);
} else {
callback(new Error('no permitido'));
}
}
}
app.use(cors(options));
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);
});