diff --git a/README.md b/README.md index b4adee8..f79eb2f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,20 @@ Extensible, distributed resource server. $ [sudo] npm install deployd -g -## CLI +## Starting / Stopping + +You can start and stop the server with the `dpd` CLI or with the node module. + + var dpd = require('deployd') + .use('http://localhost:3333') + // optionally specify which storage resource to use + // currently only mongodb is supported + .storage('mongodb://localhost/my-dpd-storage') + // tell deployd to listen + .listen() + ; + +or $ dpd $ deployd is running at http://localhost:2304 diff --git a/lib/deployd.js b/lib/deployd.js index 01e64d3..202ce1a 100644 --- a/lib/deployd.js +++ b/lib/deployd.js @@ -4,6 +4,12 @@ var dpd = require('mdoq') +/** + * Export a method to change the storage resource. + */ + +dpd.storage = require('./storage').storage + /** * Export the dpd mdoq object as the public interface. */ diff --git a/lib/resource.js b/lib/resource.js index 5ffe27e..8c02b84 100644 --- a/lib/resource.js +++ b/lib/resource.js @@ -32,7 +32,6 @@ module.exports = function (req, res, next, end) { next(); }) } - }); } else { return next(new Error('The provided module is not supported')); diff --git a/lib/storage.js b/lib/storage.js new file mode 100644 index 0000000..8a5fc0e --- /dev/null +++ b/lib/storage.js @@ -0,0 +1,23 @@ +/** + * Dependencies + */ + +var url = 'localhost/deployd'; + +module.exports = require('mdoq') + .use(function (req, res, next) { + var path = req.resource && req.resource.path; + this.url = url + (path || this.url); + next(); + }) + .require('mdoq-mongodb') +; + +/** + * Export a way to change the storage url. + */ + +module.exports.storage = function (db) { + url = db; + return this; +}; \ No newline at end of file diff --git a/lib/types/collection.js b/lib/types/collection.js index 24cf840..e373e6d 100644 --- a/lib/types/collection.js +++ b/lib/types/collection.js @@ -3,11 +3,6 @@ function format(name) { return '/' + name; } -module.exports = require('mdoq') - .use(function (req, res, next) { - var path = req.resource && req.resource.path; - this.url = 'localhost/deployd' + (path || this.url); - next(); - }) - .require('mdoq-mongodb') -; \ No newline at end of file +var storage = require('../storage'); + +module.exports = storage; \ No newline at end of file diff --git a/test/support.js b/test/support.js index dbaa1d3..17847df 100644 --- a/test/support.js +++ b/test/support.js @@ -3,7 +3,7 @@ expect = require('chai').expect dpd = require('../') root = {key: 'foo', secret: 'bar'} -server = dpd.use('http://localhost:3003') +server = dpd.use('http://localhost:3003').storage('mongodb://localhost/deployd-testing-db') client = require('mdoq').use('http://localhost:3003').use(function (req, res, next) { req.headers['x-dssh-key'] = root.key; next();