mikeal/node.couchapp.js — Issue #35: let it work behind a proxy
Author: avalez
Created: 2011-11-04 12:37:13+00:00
State: open

I cannot reach the remote server directly from my network and need to go through a proxy.

It appears request/main.js has support for proxy, but I've not managed to make it work without a patch.

One way would be to pass proxy in options, and let it specify in command line arguments, but I found it better to let request/main.js use http_proxy/https_proxy enviroment variable:

Index: node_modules/couchapp/node_modules/request/main.js
===================================================================
--- node_modules/couchapp/node_modules/request/main.js	(revision 117)
+++ node_modules/couchapp/node_modules/request/main.js	(working copy)
@@ -104,6 +104,10 @@
if (options.proxy) {
if (typeof options.proxy == 'string') options.proxy = url.parse(options.proxy)
}
+ var v = {"http:":'http_proxy', "https:":'https_proxy'}[options.uri.protocol];
+ if (!options.proxy && process.env[v]) {
+ options.proxy = url.parse(process.env[v])
+ }

options._redirectsFollowed = options._redirectsFollowed || 0
options.maxRedirects = (options.maxRedirects !== undefined) ? options.maxRedirects : 10

Hope you'll find it useful, or please let me know if there is better solution.

TODO: mention this in documentation.

Thank you.