Skip to content

Instantly share code, notes, and snippets.

@oizhaolei
Created July 30, 2015 10:58
Show Gist options
  • Save oizhaolei/057a6938a2ddaa1d1a22 to your computer and use it in GitHub Desktop.
Save oizhaolei/057a6938a2ddaa1d1a22 to your computer and use it in GitHub Desktop.
google-translate with http proxy
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