-
Notifications
You must be signed in to change notification settings - Fork 91
/
index.js
42 lines (32 loc) · 931 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
42
const express = require('express');
const cors = require('cors');
const routerApi = require('./routes');
const { logErrors, errorHandler, boomErrorHandler, ormErrorHandler } = 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(ormErrorHandler);
app.use(boomErrorHandler);
app.use(errorHandler);
app.listen(port, () => {
console.log(`Mi port ${port}`);
});