TooTallNate / superagent-proxy

`Request#proxy(uri)` superagent extension
154 stars 46 forks source link

return this if the proxy uri is null #4

Closed jarvisaoieong closed 11 years ago

jarvisaoieong commented 11 years ago

Sometimes production env is different from development env.

In production config

config = {
  proxy: null
};

In development config

config = {
  proxy: 'http://10.1.10.200:3128'
};

It is nice to have this api syntax whatever the value of proxy is null or not.

var config = require('config');
request
    .get('http://www.google.com')
    .proxy(config.proxy)
    .end(function (res) {});

otherwise, i need to write something like this

var config = require('config');
req = request.get('http://www.google.com')
if (config.proxy) {
  req = req.proxy(config.proxy);
}
req.end(function (res) {});

more ugly

TooTallNate commented 11 years ago

I'm kinda -1 on magical APIs like this. I'm throwing a TypeError on other kinds of invalid input, so we should probably do the same if there's no uri whatsoever.