-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
72 lines (58 loc) · 1.96 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//npm install
//docker build -t node-api .
//docker run --rm -it -p 3000:3000 -v "$(pwd):/app" node-api
const express = require("express");
var cors = require('cors');
var bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const path = require('path');
const info = require(path.join(__dirname,'./utils/info'));
// settings
app.set('port', process.env.PORT || 3000);
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false });
// middlewares
app.use(morgan('dev'));
app.use(cors())
// routes
app.get('/dir/:dirInicio/:dirDestino', async (req, res, next) => {
const direccionInicio = req.params.dirInicio +',santiago,chile';
const direccionDestino= req.params.dirDestino +',santiago,chile';
if (direccionInicio && direccionDestino ) {
try{
var recorrido = await info.getInfo(direccionInicio, direccionDestino);
console.log(recorrido);
res.json(recorrido);
}catch(e){
console.log(e);
}
} else {
res.status(500).json({error: 'No se han ingresado las dos variables'});
}
});
app.get('/coor/:coorInicio/:dirDestino',urlencodedParser, async (req, res, next) => {
var coInicio = req.params.coorInicio;
console.log(coInicio+',santiago,chile');
const direccionDestino= req.params.dirDestino +',santiago,chile';
if (coInicio && direccionDestino ) {
try{
var recorrido = await info.getInfoCoor(coInicio, direccionDestino);
console.log(recorrido);
res.json(recorrido);
}catch(e){
console.log(e);
}
} else {
res.status(500).json({error: 'No se han ingresado las variables'});
}
});
app.get('/', function (req, res, next) {
res.send('Holi');
});
// Starting the server
var server = app.listen(app.get('port'), function () {
var host = server.address().address
var port = server.address().port
console.log("Server listening at http://%s:%s", host, port)
})