Index: Dev/trunk/src/server/app.js
===================================================================
--- Dev/trunk/src/server/app.js	(revision 475)
+++ Dev/trunk/src/server/app.js	(revision 477)
@@ -48,5 +48,5 @@
 
     // cookies and session
-    app.use('/api/login',express.bodyParser());
+    app.use('/api',express.bodyParser());
     app.use(express.cookieParser());
     app.use(express.session({ secret: "quasi experimental design" }));
@@ -99,4 +99,61 @@
         });
 
+    // expose everything needed to fill in responses
+    // FIXME : this needs more security, now you can guess ids
+    //         and get actual survey and response data!
+    app.get(
+        '/live',
+        function(req,res){
+            res.redirect('/response.html#!/55704d6a84194c2d7ba9bec93c000e75');
+        });
+    app.get(
+        '/api/surveyRuns/:id',
+        function(req,res){
+            var id = req.params.id;
+            couch.get(id).then(function(result){
+                if ( result.type === 'SurveyRun') {
+                    res.send(200, result);
+                } else {
+                    res.send(404, {error: "Cannot find survey run "+id});
+                }
+            }, function(error){
+                res.send(404, {error: "Cannot find survey run "+id});
+            });
+        });
+    app.get(
+        '/api/responses/:id',
+        function(req,res){
+            var id = req.params.id;
+            couch.get(id).then(function(result){
+                if ( result.type === 'Response') {
+                    res.send(200, result);
+                } else {
+                    res.send(404, {error: "Cannot find response "+id});
+                }
+            }, function(error){
+                res.send(404, {error: "Cannot find response "+id});
+            });
+        });
+    app.post(
+        '/api/responses',
+        function(req,res){
+            console.log(req.body);
+            couch.post(req.body).then(function(result){
+                res.send(200, result);
+            }, function(error){
+                res.send(500, error);
+            });
+        });
+    app.put(
+        '/api/responses/:id',
+        function(req,res){
+            var id = req.params.id;
+            couch.put(id,req.body).then(function(result){
+                res.send(200, result);
+            }, function(error){
+                res.send(500, error);
+            });
+        });
+    
     // data is proxied to couch
     app.use('/api/data', ensureAuthenticated);
@@ -135,5 +192,4 @@
 function responseToVariables(response) {
     var result = flattenObject(response.answers);
-    result.respondent = response.id;
     return result;
 }
@@ -143,11 +199,22 @@
     (function agg(val,key,res){
         if ( _.isObject(val) ) {
-            _.forEach(val, function(v,k){
-                agg(v,(key ? key+'.' : '')+k,res);
-            });
+            var keys = _.keys(val);
+            // FIXME : dirty hack for questions with only one input
+            if ( keys.length === 1 ) {
+                agg(val[keys[0]],key,res);
+            } else {
+                _.forEach(val, function(v,k){
+                    agg(v,(key ? key+'.' : '')+k,res);
+                });
+            }
         } else if ( _.isArray(val) ) {
-            _.forEach(val, function(v,i){
-                agg(v,(key ? key+'.' : '')+i,res);
-            });
+            // FIXME : dirty hack for questions with only one input
+            if ( val.length === 1 ) {
+                agg(val[0],key,res);
+            } else {
+                _.forEach(val, function(v,i){
+                    agg(v,(key ? key+'.' : '')+i,res);
+                });
+            }
         } else {
             res[key] = val;
Index: Dev/trunk/src/server/config/couchdb-design-docs.js
===================================================================
--- Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 475)
+++ Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 477)
@@ -33,4 +33,11 @@
                 map: function(doc){
                     emit(doc.type, doc);
+                }
+            },
+            typeless: {
+                map: function(doc){
+                    if ( !doc.type ) {
+                        emit(doc._id, doc);
+                    }
                 }
             }
Index: Dev/trunk/src/server/util/couch.coffee
===================================================================
--- Dev/trunk/src/server/util/couch.coffee	(revision 475)
+++ Dev/trunk/src/server/util/couch.coffee	(revision 477)
@@ -9,4 +9,7 @@
         url = "#{@url}/#{id}"
         couchRequest 'GET', url
+    post: (doc) ->
+        url = "#{@url}"
+        couchRequest 'POST', url, doc
     put: (id, doc) ->
         url = "#{@url}/#{id}"
