diff --git a/index.js b/index.js new file mode 100644 index 0000000..3ecdb87 --- /dev/null +++ b/index.js @@ -0,0 +1,42 @@ +// 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 + +// Import required modules. +let express = require('express'); +let fs = require('fs'); +let bikeData = JSON.parse(fs.readFileSync('data.json', 'utf8')); + +// Initialize our Express app. +let app = express(); + +const filterStations = (stations, stationId) => { +let returnObject; + stations.map((o,index)=>{ + if(o.extra.uid == stationId){ + returnObject = o; + } + }); + return returnObject; +}; + +// Generate a simple API +app.get('/', function(req, res) { + res.send("Hey there! Thanks for visting the site!"); +}); + +// Generate a simple dashboard page. +app.get('/stations', (req, res) => { + if(req.param('stationId')){ + let returnValue = {status:"not found"}; + returnValue = filterStations(bikeData.network.stations, req.param('stationId')); + res.json(returnValue); + }else{ + res.json({status:"error"}); + } +}); + +// Listen for incoming requests and serve them. +app.listen(process.env.PORT || 3000);