如何启动对一系列链接的请求,然后在所有请求都解决之后,使用Express呈现结果?

I am trying to use axios and express to get an array of links from a page, harvest data at each link, and display results to the user. The process I'd like to implement is:

  1. Run axios.get(targetPage), harvest the links on the target page, save to an array
  2. Run run axios.all to get a response from link
  3. Harvest data from each response
  4. Display to user

Below is my app.get function:

app.get('/search', function (req, res) {
    var context = {};
    context.resources = [];
    var promises = [];
    var year = req.query.year;
    var targetPage = endpoint + year;
    axios.get(targetPage).then(resp => {
        var $ = cheerio.load(resp.data);
        var pages = []
        $('queryStr').each(function (i, ele) { pages.push(endpoint + $(ele).attr("href")) });
        context.links = pages;
        pages.forEach( link => promises.push( axios.get(link) ));
    }).then(axios.all(promises)).then( responses => {
        responses.forEach( resp => {
            var resource = {};
            resource.link = resp.url;
            var $ = cheerio.load(resp.data)
            resource.title = $('query').text()
            context.resources.push(resource);
        })
    }).then( () => {
        res.render('search', context);
    })
})

I have verified that the urls in the pages[] array are valid. I have tried calling res.render after the first axios.get call, and it successfully rendered my response. I have separately tested the logic in the forEach and verified that it works for each url. I'm getting an error message at the then block immediately following axios.all, which states that responses returned by axios.all is undefined. the Here is the error message:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined

谢谢阅读。