summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-06-28 23:22:57 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-06-28 23:22:57 +0200
commit9c933e4eb578b77d625efe487866e7433d729666 (patch)
tree9e6914d8c417294df7c25b517410f0ce3165e84a
downloadcollection-json-explorer-9c933e4eb578b77d625efe487866e7433d729666.tar.gz
collection-json-explorer-9c933e4eb578b77d625efe487866e7433d729666.tar.bz2
collection-json-explorer-9c933e4eb578b77d625efe487866e7433d729666.tar.xz
collection-json-explorer-9c933e4eb578b77d625efe487866e7433d729666.zip
o Initial import of application/vnd.collection+json explorer.
-rw-r--r--.gitignore1
-rw-r--r--app.js28
-rw-r--r--package.json13
-rw-r--r--public/stylesheets/style.css8
-rw-r--r--routes/index.js37
-rw-r--r--views/data.jade49
-rw-r--r--views/index.jade11
-rw-r--r--views/layout.jade7
8 files changed, 154 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..509fcef
--- /dev/null
+++ b/app.js
@@ -0,0 +1,28 @@
+var express = require('express')
+ , routes = require('./routes')
+ , http = require('http');
+
+var app = express();
+
+app.configure(function(){
+ app.set('port', process.env.PORT || 3000);
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.favicon());
+ app.use(express.logger('dev'));
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+});
+
+app.configure('development', function(){
+ app.use(express.errorHandler());
+});
+
+app.get('/', routes.index);
+app.get('/render', routes.render);
+
+http.createServer(app).listen(app.get('port'), function(){
+ console.log("Express server listening on port " + app.get('port'));
+});
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..cc5cd03
--- /dev/null
+++ b/package.json
@@ -0,0 +1,13 @@
+{
+ "name": "application-name",
+ "version": "0.0.1",
+ "private": true,
+ "scripts": {
+ "start": "node app"
+ },
+ "dependencies": {
+ "express": "3.0.0beta4",
+ "collection_json": "git+http://trygvis.dyndns.org/~trygvis/git/2012/06/collection_json.git",
+ "jade": "*"
+ }
+}
diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css
new file mode 100644
index 0000000..30e047d
--- /dev/null
+++ b/public/stylesheets/style.css
@@ -0,0 +1,8 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+} \ No newline at end of file
diff --git a/routes/index.js b/routes/index.js
new file mode 100644
index 0000000..9bd03cb
--- /dev/null
+++ b/routes/index.js
@@ -0,0 +1,37 @@
+var http = require('http')
+ , url = require('url')
+ , collection_json = require('collection_json');
+
+exports.index = function(req, res){
+ res.render('index', { title: 'Express' });
+};
+
+exports.render = function(req, res){
+ var options = url.parse(req.query.url);
+ options.method = 'GET';
+ options.headers = {
+ accept: 'application/vnd.collection+json'
+ };
+ var clientReq = http.request(options, function(clientRes) {
+ console.log('STATUS: ' + clientRes.statusCode);
+ console.log('HEADERS: ' + JSON.stringify(clientRes.headers));
+ clientRes.setEncoding('utf8');
+ var body = "";
+ clientRes.on('data', function (chunk) {
+ body += chunk;
+ });
+ clientRes.on('end', function (chunk) {
+ var doc = collection_json.fromObject(JSON.parse(body));
+ res.render('data', {
+ title: 'Rendering ' + req.query.url,
+ doc: doc,
+ headers: clientRes.headers,
+ raw: body,
+ formattedRaw: JSON.stringify(JSON.parse(body), null, ' ') });
+ });
+ });
+ clientReq.on('error', function() {
+ res.render('index', { title: 'Failed to render ' + req.query.url });
+ });
+ clientReq.end();
+};
diff --git a/views/data.jade b/views/data.jade
new file mode 100644
index 0000000..3051d63
--- /dev/null
+++ b/views/data.jade
@@ -0,0 +1,49 @@
+extends layout
+
+block content
+ h1= title
+ p Welcome to #{title}
+
+ form(action="/render")
+ p
+ label URL:
+ input(name="url", value="http://p2k12.bitraf.no/checkins-trygvis.php")
+ input(type="submit", value="Render")
+
+ ul
+ li
+ a(href="#items") Items
+ li
+ a(href="#headers") Headers
+ li
+ a(href="#body") Raw body
+ li
+ a(href="#formatted-body") Formatted body
+
+ a(id="items")
+ h1
+ a(href="#items") Items
+ each item, i in doc.items
+ h2 Item ##{i+1}
+ h3 Data
+ ul
+ each data in item.data
+ li #{data.name}: #{data.value}
+
+ a(id="headers")
+ h1
+ a(href="#headers") Headers
+ pre
+ each value, key in headers
+ span #{key}: #{value}
+ br
+
+ a(id="body")
+ h1
+ a(href="#body") Raw body
+ pre= raw
+
+ a(id="formatted-body")
+ h1
+ a(href="#formatted-body") Formatted body
+ pre= formattedRaw
diff --git a/views/index.jade b/views/index.jade
new file mode 100644
index 0000000..55ed3d4
--- /dev/null
+++ b/views/index.jade
@@ -0,0 +1,11 @@
+extends layout
+
+block content
+ h1= title
+ p Welcome to #{title}
+
+ form(action="/render")
+ p
+ label URL:
+ input(name="url", value="http://p2k12.bitraf.no/checkins-trygvis.php")
+ input(type="submit", value="Render")
diff --git a/views/layout.jade b/views/layout.jade
new file mode 100644
index 0000000..1b7b305
--- /dev/null
+++ b/views/layout.jade
@@ -0,0 +1,7 @@
+doctype 5
+html
+ head
+ title= title
+ link(rel='stylesheet', href='/stylesheets/style.css')
+ body
+ block content \ No newline at end of file