diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-02 18:11:17 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-02 18:12:08 +0200 |
commit | 217e98f75fd6774764b0ac924c6f642bff2dfb18 (patch) | |
tree | 83b9ee2fb1a8d52f9c1132ea1da2b1df52b3508d /routes | |
parent | 991e7cf0fe0197b9ece4fdc985afb7a1c9c258a0 (diff) | |
download | collection-json-explorer-217e98f75fd6774764b0ac924c6f642bff2dfb18.tar.gz collection-json-explorer-217e98f75fd6774764b0ac924c6f642bff2dfb18.tar.bz2 collection-json-explorer-217e98f75fd6774764b0ac924c6f642bff2dfb18.tar.xz collection-json-explorer-217e98f75fd6774764b0ac924c6f642bff2dfb18.zip |
o Adding support for queries.
Diffstat (limited to 'routes')
-rw-r--r-- | routes/index.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/routes/index.js b/routes/index.js index a5b1bdc..efed59c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,6 +1,7 @@ -var http = require('http') +var collection_json = require('collection_json') + , http = require('http') , url = require('url') - , collection_json = require('collection_json'); + , _ = require('underscore'); function urlgenerator(req) { var host = req.headers.host; @@ -24,7 +25,16 @@ exports.render = function(req, res) { err: err }); } - fetchCollection(req.query.url, function(err, headers, body) { + var u = url.parse(req.query.url, true); + var params = _.reduce(req.query, function(q, value, key) { + if(!key.match(/^param-/)) { + return q; + } + q[key.substr(6)] = value; + return q; + }, {}); + u.query = _.extend({}, u.query, params); + fetchCollection(url.format(u), function(err, headers, body) { if(err) { sendErr(err); } @@ -47,6 +57,7 @@ exports.render = function(req, res) { isUrl: isUrl, urlgenerator: urlgenerator(req), url: req.query.url, + params: params, collection: collection, headers: headers, rawBody: body, |