Index: Dev/trunk/src/server/app.js
===================================================================
--- Dev/trunk/src/server/app.js	(revision 468)
+++ Dev/trunk/src/server/app.js	(revision 470)
@@ -43,11 +43,22 @@
     app.use(express.favicon());
 
+    // cookies and session
+    app.use('/api/login',express.bodyParser());
     app.use(express.cookieParser());
-    app.use(express.bodyParser());
     app.use(express.session({ secret: "quasi experimental design" }));
 
-    // initialize passport
+    // passport
     app.use(passport.initialize());
     app.use(passport.session());
+    function ensureAuthenticated(req,res,next){
+        if (!req.user) {
+            return res.send(401,{error:"Login before accessing API."});
+        } else {
+            return next();
+        }
+    }
+    function returnUser(req,res) {
+        res.send(200, req.user);
+    }
 
     // static resources
@@ -62,11 +73,6 @@
     });
 
-    
-    // url to login (might work on others as well?)
-    // you should then have a session to work with
-    // should return a user info object
-    function returnUser(req,res) {
-        res.send(200, req.user);
-    }
+
+    // post to this url to login
     app.post(
         '/api/login',
@@ -74,13 +80,5 @@
         returnUser);
 
-    // ensure we're authenticated on API calls
-    function ensureAuthenticated(req,res,next){
-        if (!req.user) {
-            return res.send(401,{error:"Login before accessing API."});
-        } else {
-            return next();
-        }
-    }
-    
+    // return the info for the current logged in user
     app.get(
         '/api/login',
@@ -88,4 +86,5 @@
         returnUser);
 
+    // explicitly logout this user
     app.post(
         '/api/logout',
@@ -96,4 +95,9 @@
         });
 
+    // data is proxied to couch
+    app.use('/api/data', ensureAuthenticated);
+    app.use('/api/data', proxy(settings.couchDbURL));
+
+    // generate CSV download of responses
     app.get(
         '/api/surveyRuns/:id/responses.csv',
@@ -109,8 +113,4 @@
         });
     
-    // forward to couch
-    app.use('/api/data', ensureAuthenticated);
-    app.use('/api/data', proxy(settings.couchDbURL));
-
     return app;
 
Index: Dev/trunk/src/server/config/config-couchdb.js
===================================================================
--- Dev/trunk/src/server/config/config-couchdb.js	(revision 468)
+++ Dev/trunk/src/server/config/config-couchdb.js	(revision 470)
@@ -66,30 +66,30 @@
         designDocs = stringifyFunctions(designDocs);
         return q.all(_.map(designDocs, function(doc,docUrl){
-            var configAction = doc.__configAction;
+            var configAction = doc.__configAction || "replace";
             delete doc.__configAction;
             switch (configAction) {
-                case "ignore":
-                    console.log(docUrl+" ignored.");
+            case "ignore":
+                console.log(docUrl+" ignored.");
                 break;
-                case "update":
-                    console.log(docUrl+" updating.");
-                    return dbRequest('GET',docUrl)
-                    .then(function(oldDoc){
-                        _.extend(oldDoc,doc);
-                        return dbRequest('PUT',docUrl,oldDoc);
-                    },function(){
-                        return dbRequest('PUT',docUrl,doc);
-                    });
-                break;
-                case "replace":
-                default:
-                    console.log(docUrl+" replacing.");
-                    return dbRequest('GET',docUrl)
-                    .then(function(oldDoc){
-                        _.extend(doc,_.pick(oldDoc,'_id','_rev'));
-                        return dbRequest('PUT',docUrl,doc);
-                    },function(){
-                        return dbRequest('PUT',docUrl,doc);
-                    });
+            case "update":
+                console.log(docUrl+" updating.");
+                return dbRequest('GET',docUrl)
+                .then(function(oldDoc){
+                    _.extend(oldDoc,doc);
+                    return dbRequest('PUT',docUrl,oldDoc);
+                },function(){
+                    return dbRequest('PUT',docUrl,doc);
+                });
+            case "replace":
+                console.log(docUrl+" replacing.");
+                return dbRequest('GET',docUrl)
+                .then(function(oldDoc){
+                    _.extend(doc,_.pick(oldDoc,'_id','_rev'));
+                    return dbRequest('PUT',docUrl,doc);
+                },function(){
+                    return dbRequest('PUT',docUrl,doc);
+                });
+            default:
+                console.warn("Unknown action",configAction);
                 break;
             }
Index: Dev/trunk/src/server/standalone.js
===================================================================
--- Dev/trunk/src/server/standalone.js	(revision 468)
+++ 	(revision )
@@ -1,25 +1,0 @@
-var fs = require("fs");
-var https = require("https");
-var os = require("os");
-var _ = require("underscore");
-
-var app = require('./app').App({
-    couchDbURL: 'http://localhost:5984/qed'
-});
-
-var httpsOptions = {
-    key: fs.readFileSync(__dirname+'/../qed-server.key'),
-    cert: fs.readFileSync(__dirname+'/../qed-server.pem')
-};
-
-var server = https.createServer(httpsOptions, app);
-server.listen(8443);
-
-console.log(
-    "Listening on " + 
-    _.chain(os.networkInterfaces())
-     .map(function(value,key){ return value; })
-     .flatten()
-     .filter(function(intf){ return intf.family === "IPv4" && !intf.internal; })
-     .reduce(function(urls, intf){ return urls+', http://'+intf.address+':8443/'; }, "http://127.0.0.1:8443/")
-     .value() + ".");
Index: Dev/trunk/src/server/util/q-request.js
===================================================================
--- Dev/trunk/src/server/util/q-request.js	(revision 468)
+++ Dev/trunk/src/server/util/q-request.js	(revision 470)
@@ -9,7 +9,5 @@
     dfd.response = q.defer();
     
-    options = options
-        ? _.clone(options)
-        : {};
+    options = options ? _.clone(options) : {};
     options.uri = url || options.uri;
     
Index: Dev/trunk/src/server/util/simple-http-proxy.js
===================================================================
--- Dev/trunk/src/server/util/simple-http-proxy.js	(revision 468)
+++ Dev/trunk/src/server/util/simple-http-proxy.js	(revision 470)
@@ -3,7 +3,7 @@
  * Module dependencies
  */
-var url = require('url')
-    , join = require('path').join
-    , protocols = {
+var url = require('url'),
+    join = require('path').join,
+    protocols = {
         http: require('http'),
         https: require('https')
