Ignore:
Timestamp:
03/15/14 01:00:23 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Support different environments with QED_ENV. If dev, run against qed-dev database, if production, run against qed database. The UI indicates if we are running in anything but production mode.
  • Return undefined if we allow page leaves, because null is treated as a value.
  • Changed format of design docs, so it can work for different databases.
  • Use correct design documents in configCouch, so server now actually updates them when it starts.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/app.js

    r508 r519  
    1414  ;
    1515
    16 function assertSetting(name, settings, validate) {
    17     if ( typeof settings[name] === 'undefined' ) {
    18         throw new Error("Required setting '"+name+"' undefined.");
    19     }
    20     if ( _.isFunction(validate) && !validate(settings[name]) ) {
    21         throw new Error("Setting '"+name+"' with value '"+settings[name]+"' is invalid.");
    22     }
    23 }
    24 
    25 exports.App = function(settings) {
    26 
    27     assertSetting("couchServerURL", settings, _.isString);
    28     assertSetting("dbName", settings, _.isString);
    29     var couch = new CouchDB(settings.couchServerURL,settings.dbName);
     16exports.App = function(env) {
     17
     18    assertSetting("couchServerURL", env, _.isString);
     19    assertSetting("dbName", env, _.isString);
     20    assertSetting("mode", env, _.isString);
     21    var couch = new CouchDB(env.couchServerURL,env.dbName);
    3022   
    3123    var schema = require("./config/couchdb-schema.json");
     
    3527            throw new Error(msg);
    3628        }
    37         return configureApp(settings,couch,schema);
     29        return configureApp(env,couch,schema);
    3830    });
    3931
    4032};
    4133
    42 function configureApp(settings,couch,schema) {
     34function configureApp(env,couch,schema) {
    4335
    4436    function clientPath(relativePath) {
     
    4638    }
    4739
    48     passport.use(new passportLocal.Strategy(function(username, password, done){
    49         if ( username === "igor" && password === "mayer" ) {
    50             done(null,{ username: "igor" });
    51         } else {
    52             done(null,false,{ message: 'Invalid credentials.' });
    53         }
    54     }));
     40    passport.use(
     41        new passportLocal.Strategy(
     42            function(username, password, done){
     43                if ( username === "igor" && password === "mayer" ) {
     44                    done(null,{ username: "igor" });
     45                } else {
     46                    done(null,false,{ message: 'Invalid credentials.' });
     47                }
     48            }));
    5549    passport.serializeUser(function(user, done) {
    5650        done(null, user.username);
     
    952946        });
    953947
     948    app.get('/api/mode',
     949        ensureMIME(JSON_MIME),
     950        function(req,res){
     951            res.send({mode:env.mode});
     952        });
     953
     954
    954955    return app;
    955956}
     
    991992    return result;
    992993}
     994
     995function assertSetting(name, settings, validate) {
     996    if ( typeof settings[name] === 'undefined' ) {
     997        throw new Error("Required setting '"+name+"' undefined.");
     998    }
     999    if ( _.isFunction(validate) && !validate(settings[name]) ) {
     1000        throw new Error("Setting '"+name+"' with value '"+settings[name]+"' is invalid.");
     1001    }
     1002}
Note: See TracChangeset for help on using the changeset viewer.