-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 802 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
const express = require('express');
const cors = require('cors')
const routerApi = require('./routes');
//middlewares
const { logErrors, errorHandler, boomErrorHandler } = require('./middlewares/error.handler')
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
const whitelist = ['http://127.0.0.1:5500/'];
const options = {
origin: (origin, callback)=>{
if(whitelist.includes(origin) || !origin){
callback(null,true);
}else{
callback(new Error('no permitido'))
}
}
}
app.use(cors());
app.get('/',(req,res) => {
res.send('hola mi server en express');
});
routerApi(app);
//usamos los middleware
app.use(logErrors);
app.use(boomErrorHandler);
app.use(errorHandler);
app.listen(port,() => {
console.log(`My port: ${port}`);
});