From 217e98f75fd6774764b0ac924c6f642bff2dfb18 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 2 Jul 2012 18:11:17 +0200 Subject: o Adding support for queries. --- routes/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'routes') 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, -- cgit v1.2.3