Skip to content
Snippets Groups Projects

2

Merged L5339 requested to merge master into Heikki
6 files
+ 1418
63
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 63
0
const express = require('express');
const router = express.Router();
const axios = require('axios');
//
router.get('/:searchkey',(req, res)=>{
var searchkey = req.params.searchkey;
var url = `http://lipas.cc.jyu.fi/api/sports-places?cityCodes=77&cityCodes=172&cityCodes=179&cityCodes=182&cityCodes=216&cityCodes=226&cityCodes=249&cityCodes=256&cityCodes=265&cityCodes=275&cityCodes=291&cityCodes=312&cityCodes=410&cityCodes=435&cityCodes=495&cityCodes=500&cityCodes=592&cityCodes=601&cityCodes=729&cityCodes=850&cityCodes=892&cityCodes=931&cityCodes=992&searchString=${searchkey}`;
var placeIDs;
var placeNames=[];
//using axios lib to making http get request to lipas. // npm install axios
axios.get(url).then(async response=>{
console.log(response.status)
console.log(response.data)
if (response.status==206 || response.status==200){
//res.send(response.data)
placeIDs = response.data;
for(const element of placeIDs){
const ID = element.sportsPlaceId;
url2=`http://lipas.cc.jyu.fi/api/sports-places/${ID}`;
await axios.get(url2).then(resp=>{
if(resp.status==200){
console.log(resp.status);
console.log(resp.data.name);
placeNames.push({
id : ID,
name : resp.data.name
});
}
}).catch(e=>{
console.log(e)
});
}
res.send(placeNames);
}else{
res.send(response.status);
}
}).catch(error=>{
res.status(400).send(error);
});
});
module.exports = router;
Loading