Working version
This commit is contained in:
parent
4ec202c958
commit
60a9c29c9a
27
index.js
27
index.js
@ -1,16 +1,12 @@
|
||||
// Request all stuff from citybikes.es
|
||||
//save to json all 500 ms
|
||||
//https://api.citybik.es/v2/networks/valenbisi?fields=stations
|
||||
|
||||
//Setup a express get server with token
|
||||
|
||||
'use strict';
|
||||
// Import required modules.
|
||||
let express = require('express');
|
||||
let fs = require('fs');
|
||||
let bikeData = JSON.parse(fs.readFileSync('data.json', 'utf8'));
|
||||
let axios = require('axios');
|
||||
let bikeData = {};
|
||||
|
||||
// Initialize our Express app.
|
||||
let app = express();
|
||||
let requestDataTimer = setInterval(requestData, 3000);
|
||||
|
||||
const filterStations = (stations, stationId) => {
|
||||
let returnObject;
|
||||
@ -29,14 +25,25 @@ app.get('/', function(req, res) {
|
||||
|
||||
// Generate a simple dashboard page.
|
||||
app.get('/stations', (req, res) => {
|
||||
if(req.param('stationId')){
|
||||
if(req.query.stationId){
|
||||
let returnValue = {status:"not found"};
|
||||
returnValue = filterStations(bikeData.network.stations, req.param('stationId'));
|
||||
returnValue = filterStations(bikeData.network.stations, req.query.stationId);
|
||||
res.json(returnValue);
|
||||
}else{
|
||||
res.json({status:"error"});
|
||||
}
|
||||
});
|
||||
|
||||
function requestData(){
|
||||
|
||||
axios.get('https://api.citybik.es/v2/networks/valenbisi',{headers: {'Accept-Encoding': 'gzip, deflate, br'}})
|
||||
.then(function (response) {
|
||||
//console.log(response);
|
||||
bikeData = response.data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
// Listen for incoming requests and serve them.
|
||||
app.listen(process.env.PORT || 3000);
|
||||
|
Loading…
Reference in New Issue
Block a user