diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-22 20:43:04 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-22 20:43:04 +0200 |
commit | 56edd9584cb964f75ccaeae4db9d0040b71ffe5f (patch) | |
tree | 7e333b514df3db8af9bbe65d4aee9d7f8ba70b78 /routes | |
parent | c677e79c1227eedb656ad1a6830c38c64a4c0e4b (diff) | |
download | collection-json-explorer-56edd9584cb964f75ccaeae4db9d0040b71ffe5f.tar.gz collection-json-explorer-56edd9584cb964f75ccaeae4db9d0040b71ffe5f.tar.bz2 collection-json-explorer-56edd9584cb964f75ccaeae4db9d0040b71ffe5f.tar.xz collection-json-explorer-56edd9584cb964f75ccaeae4db9d0040b71ffe5f.zip |
o Better layout of the data table.
Using a <table> instead of <dl> as the dl headings was collapsed by
at least Chrome.
o Adding mail logging.
Diffstat (limited to 'routes')
-rw-r--r-- | routes/index.js | 36 |
1 files changed, 7 insertions, 29 deletions
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); - }); -} |