Permalink
Browse files

configure database for production

  • Loading branch information...
1 parent 7ae1ae2 commit 43ef9d0ed9b339e448d47893131cd8173ebc8185 @zaach zaach committed Dec 12, 2012
Showing with 29 additions and 7 deletions.
  1. +5 −0 .awsbox.json
  2. +2 −0 bin/api
  3. +4 −2 etc/config.js
  4. +4 −2 lib/db.js
  5. +13 −2 lib/db/couchbase.js
  6. +1 −1 package.json
View
@@ -5,6 +5,11 @@
"bin/static",
"bin/builder"
],
+ "env": {
+ "NODE_ENV": "production",
+ "DB_STORE": "couchbase",
+ "PUBLIC_URL": "http://dev.tobmog.org/"
+ },
"hooks": {
"postcreate": "scripts/post_create.sh"
}
View
@@ -51,4 +51,6 @@ apiLoader(server, function(err) {
process.on('SIGTERM', function() {
server.stop();
+ // db won't close unless exit called explicitly
+ process.exit(0);
});
View
@@ -30,10 +30,12 @@ var config = module.exports = {
scheme: 'hawk'
}
},
+ env: process.env.NODE_ENV || 'development',
db: {
+ store: process.env.DB_STORE || 'json',
hosts: [ 'localhost:8091' ],
- username: 'Administration',
- password: process.env.DB_PASSWORD || null,
+ username: 'Administrator',
+ password: process.env.DB_PASSWORD || 'password',
bucket: process.env.DB_BUCKET || 'default'
}
};
View
@@ -1,3 +1,5 @@
+var config = require('../etc/config.js');
-// TODO select driver based on config
-module.exports = require('./db/json');
+module.exports = config.db.store === 'couchbase' ?
+ require('./db/couchbase') :
+ require('./db/json');
View
@@ -2,13 +2,16 @@ var couchbase = require('couchbase');
var db;
+var onError = function(e){
+ console.log('Couchbase error: ' + e);
+};
+
module.exports = {
connect: function(options, cb) {
- console.error('options', options);
couchbase.connect(options, function(err, bucket) {
- console.error('connection fail!!!', err);
if (err) cb(err);
db = bucket;
+ db.on('error', onError);
cb(null);
});
return this;
@@ -40,5 +43,13 @@ module.exports = {
else cb(null, meta);
});
return this;
+ },
+ getAuthKey: function(email, cb) {
+ db.get(email, function (err, doc, meta) {
+ if (err) return cb(err);
+ if (!doc) return cb('No account found for ' + email);
+ cb(null, doc.pass);
+ });
+ return this;
}
};
View
@@ -14,7 +14,7 @@
"hawk": "0.0.6"
},
"optionalDependencies": {
- "couchbase": "0.0.4"
+ "couchbase": "0.0.7"
},
"devDependencies": {
"should": "1.2.1",

0 comments on commit 43ef9d0

Please sign in to comment.