-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (31 loc) · 996 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
43
44
45
require('./config/conexion');
const express = require('express');
const cors = require('cors')
const port = (process.env.PORT || 3000)
const app = express();
//admitir tipos de datos
app.use(express.json())
app.use(cors())
// configurar cors
var allowlist = []
var corsOptionsDelegate = function (req, callback) {
var corsOptions;
if (allowlist.indexOf(req.header('Origin')) !== -1) {
corsOptions = { origin: true } // reflect (enable) the requested origin in the CORS response
} else {
corsOptions = { origin: false } // disable CORS for this request
}
callback(null, corsOptions) // callback expects two parameters: error and options
}
// configurar puerto
app.set('port',port)
// rutas
app.use('/api',require('./routes/estaciones'))
// iniciar express
app.listen(app.get('port'),(error)=>{
if (error) {
console.log('error al iniciar servidor: '+ error)
} else {
console.log('Servidor inicado en el puerto '+port)
}
})