Created
July 30, 2015 10:58
-
-
Save oizhaolei/057a6938a2ddaa1d1a22 to your computer and use it in GitHub Desktop.
google-translate with http proxy
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
node-google-translate/lib/main.js | |
// Closure that returns a function for making a | |
// GET request to Google with an apiKey | |
-var getRequestWithApi = function(apiKey) { | |
+var getRequestWithApi = function(apiKey, httpProxy) { | |
return function(path, data, done) { | |
var url = apiBase + path + '?' + querystring.stringify(_.extend({ 'key': apiKey }, data)); | |
+ | |
+ if (httpProxy != '') { | |
+ request = request.defaults({proxy: httpProxy}); | |
+ } | |
request.get(url, globalResponseHandler(done)); | |
}; | |
}; | |
@@ -126,12 +130,12 @@ var splitArraysForGoogle = function(arr, result) { | |
// PUBLIC API | |
//// | |
-module.exports = function(apiKey, newConcurrentLimit) { | |
+module.exports = function(apiKey, httpProxy, newConcurrentLimit) { | |
// Set new concurrent limit for async calls if specified | |
concurrentLimit = newConcurrentLimit || concurrentLimit; | |
- var get = getRequestWithApi(apiKey), | |
+ var get = getRequestWithApi(apiKey, httpProxy), | |
api = {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment