From 56edd9584cb964f75ccaeae4db9d0040b71ffe5f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 22 Jul 2012 20:43:04 +0200 Subject: o Better layout of the data table. Using a instead of
as the dl headings was collapsed by at least Chrome. o Adding mail logging. --- routes/index.js | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'routes') diff --git a/routes/index.js b/routes/index.js index 702ec0f..fff06b6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,4 +1,5 @@ var collection_json = require('collection_json') + , explorer = require('../lib/explorer.js') , http = require('http') , url = require('url') , util = require('util') @@ -162,16 +163,16 @@ exports.render = function(req, res) { var u = url.parse(req.query.url, true); var params = extractParams(req.query); u.query = _.extend({}, u.query, params); - fetchCollection(url.format(u), function(err, httpResponse) { + explorer.fetchCollection(url.format(u), function(err, result) { if(err) { - sendErr(req, res, err, httpResponse); + sendErr(req, res, err, result); return; } var parsedBody; try { - parsedBody = JSON.parse(httpResponse.body); + parsedBody = JSON.parse(result.body); } catch(e) { - sendErr(req, res, 'Unable to parse JSON: ' + e, httpResponse); + sendErr(req, res, 'Unable to parse JSON: ' + e, result); return; } res.render('data', { @@ -179,33 +180,10 @@ exports.render = function(req, res) { url: req.query.url, referer: req.query.referer, params: params, root: collection_json.fromObject(parsedBody), - httpResponse: httpResponse, + httpResponse: result.res, parsedBody: parsedBody, - rawBody: httpResponse.body + rawBody: result.body }); }); }; -function fetchCollection(u, cb) { - var options = url.parse(u); - options.headers = { - accept: 'application/vnd.collection+json' - }; - var req = http.get(options, function(res) { - res.setEncoding('utf8'); - var body = ''; - res.on('data', function (chunk) { - body += chunk; - }); - res.on('end', function () { - cb(undefined, { - statusCode: res.statusCode, - status: '', - headers: res.headers, - body: body - }); - }); - }).on('error', function() { - cb('Unable to fetch ' + u); - }); -} -- cgit v1.2.3