Last change
on this file since 475 was
470,
checked in by hendrikvanantwerpen, 12 years ago
|
Reorganized app and fixed some style issues.
Was looking for a bug where the proxy would not forward requests to the
database. This is somehow magically resolved now.
|
File size:
684 bytes
|
Rev | Line | |
---|
[468] | 1 | var q = require('q'), |
---|
| 2 | request = require('request'), |
---|
[466] | 3 | url = require('url'), |
---|
| 4 | _ = require('underscore'); |
---|
| 5 | |
---|
[468] | 6 | module.exports = function(url, options) { |
---|
[466] | 7 | |
---|
[468] | 8 | var dfd = q.defer(); |
---|
| 9 | dfd.response = q.defer(); |
---|
| 10 | |
---|
[470] | 11 | options = options ? _.clone(options) : {}; |
---|
[468] | 12 | options.uri = url || options.uri; |
---|
[466] | 13 | |
---|
[468] | 14 | request(options,function(err,res,body){ |
---|
| 15 | if ( err ) { |
---|
| 16 | dfd.response.reject(err); |
---|
| 17 | } else { |
---|
| 18 | if ( res.statusCode >= 200 && res.statusCode < 300 ) { |
---|
| 19 | dfd.resolve(body); |
---|
| 20 | } else { |
---|
| 21 | dfd.reject(body); |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | dfd.response.resolve(res); |
---|
[466] | 25 | }); |
---|
[468] | 26 | |
---|
| 27 | return dfd.promise; |
---|
| 28 | |
---|
[466] | 29 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.