Index: Dev/trunk/src/server/app.js
===================================================================
--- Dev/trunk/src/server/app.js	(revision 516)
+++ Dev/trunk/src/server/app.js	(revision 519)
@@ -14,18 +14,10 @@
   ;
 
-function assertSetting(name, settings, validate) {
-    if ( typeof settings[name] === 'undefined' ) {
-        throw new Error("Required setting '"+name+"' undefined.");
-    }
-    if ( _.isFunction(validate) && !validate(settings[name]) ) {
-        throw new Error("Setting '"+name+"' with value '"+settings[name]+"' is invalid.");
-    }
-}
-
-exports.App = function(settings) {
-
-    assertSetting("couchServerURL", settings, _.isString);
-    assertSetting("dbName", settings, _.isString);
-    var couch = new CouchDB(settings.couchServerURL,settings.dbName);
+exports.App = function(env) {
+
+    assertSetting("couchServerURL", env, _.isString);
+    assertSetting("dbName", env, _.isString);
+    assertSetting("mode", env, _.isString);
+    var couch = new CouchDB(env.couchServerURL,env.dbName);
     
     var schema = require("./config/couchdb-schema.json");
@@ -35,10 +27,10 @@
             throw new Error(msg);
         }
-        return configureApp(settings,couch,schema);
+        return configureApp(env,couch,schema);
     });
 
 };
 
-function configureApp(settings,couch,schema) {
+function configureApp(env,couch,schema) {
 
     function clientPath(relativePath) {
@@ -46,11 +38,13 @@
     }
 
-    passport.use(new passportLocal.Strategy(function(username, password, done){
-        if ( username === "igor" && password === "mayer" ) {
-            done(null,{ username: "igor" });
-        } else {
-            done(null,false,{ message: 'Invalid credentials.' });
-        }
-    }));
+    passport.use(
+        new passportLocal.Strategy(
+            function(username, password, done){
+                if ( username === "igor" && password === "mayer" ) {
+                    done(null,{ username: "igor" });
+                } else {
+                    done(null,false,{ message: 'Invalid credentials.' });
+                }
+            }));
     passport.serializeUser(function(user, done) {
         done(null, user.username);
@@ -952,4 +946,11 @@
         });
 
+    app.get('/api/mode',
+        ensureMIME(JSON_MIME),
+        function(req,res){
+            res.send({mode:env.mode});
+        });
+
+
     return app;
 }
@@ -991,2 +992,11 @@
     return result;
 }
+
+function assertSetting(name, settings, validate) {
+    if ( typeof settings[name] === 'undefined' ) {
+        throw new Error("Required setting '"+name+"' undefined.");
+    }
+    if ( _.isFunction(validate) && !validate(settings[name]) ) {
+        throw new Error("Setting '"+name+"' with value '"+settings[name]+"' is invalid.");
+    }
+}
Index: Dev/trunk/src/server/bin/check-db.js
===================================================================
--- Dev/trunk/src/server/bin/check-db.js	(revision 516)
+++ Dev/trunk/src/server/bin/check-db.js	(revision 519)
@@ -2,4 +2,5 @@
   , checkCouch = require('../config/check-couchdb')
   ;
+console.log("Running on",env.couchServerURL+env.dbName);
 checkCouch(env.couchServerURL,env.dbName)
 .then(function(res){
Index: Dev/trunk/src/server/bin/config-db-for-upgrade.js
===================================================================
--- Dev/trunk/src/server/bin/config-db-for-upgrade.js	(revision 516)
+++ Dev/trunk/src/server/bin/config-db-for-upgrade.js	(revision 519)
@@ -3,4 +3,5 @@
   , designDocs = require('../config/couchdb-upgrade-design-docs')
   ;
+console.log("Running on",env.couchServerURL+env.dbName);
 configCouch(env.couchServerURL,env.dbName,designDocs)
 .then(function(res){
Index: Dev/trunk/src/server/bin/config-db.js
===================================================================
--- Dev/trunk/src/server/bin/config-db.js	(revision 516)
+++ Dev/trunk/src/server/bin/config-db.js	(revision 519)
@@ -3,4 +3,5 @@
   , designDocs = require('../config/couchdb-design-docs')
   ;
+console.log("Running on",env.couchServerURL+env.dbName);
 configCouch(env.couchServerURL,env.dbName,designDocs)
 .then(function(res){
Index: Dev/trunk/src/server/bin/heroku.js
===================================================================
--- Dev/trunk/src/server/bin/heroku.js	(revision 516)
+++ Dev/trunk/src/server/bin/heroku.js	(revision 519)
@@ -1,13 +1,11 @@
 var env = require('../env')
   , configCouch = require('../config/config-couchdb')
-  , designDocs = require('../config/config-couchdb')
+  , designDocs = require('../config/couchdb-design-docs')
   ;
 
-console.log("Running on",env.couchServerURL);
+console.log("Running on",env.couchServerURL+env.dbName);
 
-require('../app').App({
-    couchServerURL: env.couchServerURL,
-    dbName: env.dbName
-}).then(function(app){
+require('../app').App(env)
+.then(function(app){
     configCouch(env.couchServerURL,env.dbName,designDocs);
     return app;
Index: Dev/trunk/src/server/config/config-couchdb.js
===================================================================
--- Dev/trunk/src/server/config/config-couchdb.js	(revision 516)
+++ Dev/trunk/src/server/config/config-couchdb.js	(revision 519)
@@ -20,11 +20,11 @@
         }
     }).then(function(res){
-        console.log("Checking database 'qed'");
-        return server.get('qed')
+        console.log("Checking database '"+dbName+"'");
+        return server.get(dbName)
         .then(function(db){
-            console.log("Database 'qed' found.");
+            console.log("Database found.");
         },function(err){
-            console.log("Creating database 'qed'");
-            return server.put('qed');
+            console.log("Creating database.");
+            return server.put(dbName);
         });
     }).then(function(){
@@ -34,4 +34,5 @@
                 var configAction = doc.__configAction || "replace";
                 delete doc.__configAction;
+                docUrl = dbName+'/'+docUrl;
                 switch (configAction) {
                 case "ignore":
Index: Dev/trunk/src/server/config/couchdb-design-docs.js
===================================================================
--- Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 516)
+++ Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 519)
@@ -1,32 +1,11 @@
 module.exports = {
 
-    "_users/qed_admin": {
-        __configAction: "ignore",
-        _id: "org.couchdb.user:qed_admin",
-        name: "qed_admin",
-        password: "Welkom01",
-        roles: [ "qed_admin" ],
-        type: "user"
-    },
-
-    "qed/schemaInfo": {
+    "schemaInfo": {
+        _id: "schemaInfo",
         version: "4"
     },
 
-    "qed/_security": {
-        __configAction: "ignore",
-        admins: {
-            names: [],
-            roles: ["qed_admin"]
-        },
-        readers: {
-            names: [],
-            roles: ["qed_user"]
-        }
-    },
-
-    "qed/_design/protectPublished": {
+    "_design/protectPublished": {
         __configAction: "replace",
-        _id: "_design/protectPublished",
         language: "javascript",
         validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
@@ -37,7 +16,6 @@
     },
 
-    "qed/_design/default": {
+    "_design/default": {
         __configAction: "replace",
-        _id: "_design/default",
         language: "javascript",
         views: {
@@ -57,7 +35,6 @@
     },
 
-    "qed/_design/questions": {
+    "_design/questions": {
         __configAction: "replace",
-        _id: "_design/questions",
         language: "javascript",
         views: {
@@ -117,7 +94,6 @@
     },
 
-    "qed/_design/surveys": {
+    "_design/surveys": {
         __configAction: "replace",
-        _id: "_design/surveys",
         language: "javascript",
         views: {
@@ -137,7 +113,6 @@
     },
 
-    "qed/_design/surveyRuns": {
+    "_design/surveyRuns": {
         __configAction: "replace",
-        _id: "_design/surveys",
         language: "javascript",
         views: {
@@ -153,7 +128,6 @@
     },
 
-    "qed/_design/responses": {
+    "_design/responses": {
         __configAction: "replace",
-        _id: "_design/responses",
         language: "javascript",
         views: {
Index: Dev/trunk/src/server/config/couchdb-upgrade-design-docs.js
===================================================================
--- Dev/trunk/src/server/config/couchdb-upgrade-design-docs.js	(revision 516)
+++ Dev/trunk/src/server/config/couchdb-upgrade-design-docs.js	(revision 519)
@@ -1,11 +1,10 @@
 module.exports = {
 
-    "qed/schemaInfo": {
+    "schemaInfo": {
         version: "-1"
     },
 
-    "qed/_design/protectPublished": {
-        __configAction: "replace",
-        _id: "_design/protectPublished"
+    "_design/protectPublished": {
+        __configAction: "replace"
     }
 
Index: Dev/trunk/src/server/env.js
===================================================================
--- Dev/trunk/src/server/env.js	(revision 516)
+++ Dev/trunk/src/server/env.js	(revision 519)
@@ -1,6 +1,14 @@
-var couchServerURL = (process.env.CLOUDANT_URL || 'http://localhost:5984')+'/';
+var dbNames = {
+    dev: 'qed-dev',
+    production: 'qed'
+};
+var mode = process.env.QED_ENV || 'dev';
+if ( !( mode in dbNames ) ) {
+    throw new Error("Unknown environment "+mode);
+}
 module.exports = {
     port: process.env.PORT || 5000,
-    couchServerURL: couchServerURL,
-    dbName: 'qed'
+    couchServerURL: (process.env.CLOUDANT_URL || 'http://localhost:5984')+'/',
+    dbName: dbNames[mode],
+    mode: mode
 };
