Unfortunately, I also couldn't find way to make JSDOM to use
http_proxy.
You can use "request" to download your html using proxy and submit the
body to jsdom:

request({ uri:'http://www.google.com' }, function (e, r, html) {
  if (e && r.statusCode !== 200) {
    console.log("Some error message");
  } else {
    jsdom.env({html: html, scripts: [__dirname + "/static/jq.js"]}, //
load local copy of jquery.js
       function (err, window) {
           var $ = window.jQuery;
           console.log($('body').html());
       });
  }
});

Cheers,
B Simandoff
On Jan 30, 9:49 pm, Tauren Mills <tau...@groovee.com> wrote:
> Is there a way to get ALL outbound HTTP requests from node apps to use
> the HTTP_PROXY environment variable? I'm behind a corporate firewall
> and must go through a proxy.
>
> In my own code, I can successfully get through the proxy by using
> Mikeal's request:
>
> var request = require('request');
> request = request.defaults({proxy: process.env.HTTP_PROXY });
> request.get({
>   url: "http://google.com"}, function(e,r,body) {
>
>   if (body.indexOf('doctype')) {
>     console.log("Loaded google.com");
>   }
>   else {
>     console.log("Error loading google.com", e);
>   }
>
> });
>
> But what about 3rd-party libs installed via NPM? Is there a way to get
> them to recognize the HTTP_PROXY setting? Obviously, I can't hack all
> of them to update request.get with my proxy setting. And some of them
> don't use request. As you can see above, I've even setting a default
> proxy in my app logic. But as I assumed, this doesn't pass through to
> other libs. For instance, I'm trying to get this working with jsdom:
>
> var request = require('request');
> request = request.defaults({proxy: process.env.HTTP_PROXY });
> var jsdom = require('jsdom');
> jsdom.env("http://nodejs.org/dist/";, [
>   'http://code.jquery.com/jquery-1.5.min.js'
> ],
> function(errors, window) {
>   console.log("Window: ", window);
>   if (errors) {
>     console.log("Error: ",errors);
>   }
>   else {
>     console.log("There have been", window.$("a").length, "nodejs
> releases!");
>   }
>
> });
>
> This results in:
>
> Window:  undefined
> Error occurred { [Error: connect ECONNREFUSED]
>   code: 'ECONNREFUSED',
>   errno: 'ECONNREFUSED',
>   syscall: 'connect' }
>
> There must be others building Node apps behind a proxy. How do you
> deal with this?
>
> Thanks!
> Tauren

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to