router.post('/', function(req, res, next) {
console.log('req.body from root', req.body)
var tuneName = req.body.name // what is entered by user
var tune = encodeURIComponent(tuneName)
console.log('tune', tune)
var tuneUrl = 'https://thesession.org/tunes/search?q=' + tune + '&format=json'
console.log('tuneUrl', tuneUrl)
// Get first unirest call to session.org with tune entered by user
unirest.get(tuneUrl)
.end(function (response) {
console.log('response from unirest', response.body.tunes[0])
_id = response.body.tunes[0]
console.log('_id', _id)
// first render
res.render('tunes', { tunesSess: response.body.tunes[0]})
console.log('id', response.body.tunes.id)
// 2nd unirest call to session.org to get key
var tuneUrlKey = 'https://thesession.org/tunes/' + tuneOnly.id + '?format=json'
unirest.get(tuneUrlKey)
.end(function (response) {
console.log('key', response.body.settings[0].key)
res.render('tunes', {tuneSessKey: response.body.settings[0], response.body.settings[0].key})
})
})
})
})
})
})
不确定如何从第二个 url 呈现第二个 unirest 调用。我主要想从第二个 unirest api 调用中呈现信息,尽管如果我可以将两个调用都呈现到同一个页面,那就太好了。