Last active
February 6, 2017 16:16
-
-
Save David-Hackro/bc3840bf6d628883c556f32ca67c5270 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const bodyParser = require('body-parser') | |
const request = require('request') | |
const app = express() | |
const functions = require('./function') | |
app.use(bodyParser.json()) | |
app.use(bodyParser.urlencoded({ | |
extended: true | |
})) | |
var server = app.listen(process.env.PORT || 3000, function() { | |
var port = server.address().port | |
}) | |
function loadPlaces(lat, long, token) { | |
var deferred = Promise.defer(); | |
if (token != undefined || token != null) { | |
functions.getListPlacesToken(lat, long, token).then(resp => { | |
let body = JSON.parse(JSON.stringify(resp)) | |
let arrayPlaces = body.results; | |
list.push(arrayPlaces) | |
loadPlaces(lat, long, body.next_page_token,list).then(function() { | |
deferred.resolve() | |
}) | |
}) | |
} else { | |
console.log('') | |
deferred.resolve(); | |
} | |
return deferred.promise; | |
} | |
var list = []; | |
app.get('/getPlaces', (req, res) => { | |
loadPlaces(19.0356617, -98.1782189, '',list) | |
.then(function() { | |
console.log('final') | |
res.statusCode === 200 | |
res.writeHead(res.statusCode.toString()) | |
res.end('res') | |
}).catch(error => { | |
console.log(error) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment