Last active
March 3, 2017 03:36
-
-
Save sgelliott/13840b6f2f9d2ab481fcded6dc4a9188 to your computer and use it in GitHub Desktop.
Trying to match request URLs with responses received from needle.getAsync
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
var needle = require('needle'); | |
var Promise = require("bluebird"); | |
Promise.promisifyAll(needle); | |
var allPaths = ["https://google.com", "https://microsoft.com", "https://github.com"]; | |
var current = Promise.resolve(); | |
Promise.map(allPaths, function (path) { | |
current = current.then(function () { | |
console.log("path: " + path); // path shows up here correctly - it's available | |
return needle.getAsync(path, options); | |
}); | |
return current; | |
}).map(function (resp, body) { | |
return {path: "path goes here", status: resp.statusCode}; | |
}).then(function (results) { | |
/* I have no way to access the original request URL/path here for matching */ | |
console.log("results: " + JSON.stringify(results)); // this outputs 'resulst' : [{"path":"path goes here","status":200},{"path":"path goes here","status":302},{"path":"path goes here","status":200}] | |
return renderResults(results); //this simply sets 'statusResults' to 'results' for the next res.send to use - will refine once I solve the path matching issue | |
}).then(function () { | |
console.log('All Needle requests are processed!'); | |
res.send(statusResults); // | |
}).catch(function (e) { | |
console.log(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment