From bcb582c3dc0548ff8de82058422df90ff26d5b22 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Wed, 23 Dec 2015 11:41:44 +0100 Subject: [PATCH] =?UTF-8?q?WIP=20=E2=80=93=20pass=20routes=20prefix=20as?= =?UTF-8?q?=202nd=20argument=20to=20server.register?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * * * This commit was sponsored by &yet. Our friends at &yet have been supporters of Hoodie since its earliest days. <3 And they have availability for new projects! We think they’re some of the best people you can hire anywhere, but you can read what other people have to say about them and their work here: https://andyet.com/case-studies/ * * * This commit was sponsored by &yet. Our friends at &yet have been supporters of Hoodie since its earliest days. <3 And they have availability for new projects! We think they’re some of the best people you can hire anywhere, but you can read what other people have to say about them and their work here: https://andyet.com/case-studies/ --- lib/hapi.js | 33 +++++++++++++++++++-------------- lib/index.js | 18 ++++++++++++++---- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/lib/hapi.js b/lib/hapi.js index 3223ab8..6da685f 100644 --- a/lib/hapi.js +++ b/lib/hapi.js @@ -1,5 +1,3 @@ -var _ = require('lodash') - module.exports = function (config, couchConfig, callback) { var database = require('./database')(config) var usersDb = database(couchConfig.authentication_db) @@ -8,14 +6,6 @@ module.exports = function (config, couchConfig, callback) { usersDb.installUsersBehavior() .then(function () { - var defaultOpts = { - admins: couchConfig.admins, - config: config, - database: database, - prefix: '/hoodie/account', - usersDb: usersDb - } - callback(null, [ require('inert'), require('h2o2') @@ -27,12 +17,27 @@ module.exports = function (config, couchConfig, callback) { register: plugin, options: {config: config} } - }), { + }).concat([[{ register: require('hoodie-server-account'), - options: defaultOpts + options: { + admins: couchConfig.admins, + config: config, + database: database, + usersDb: usersDb + } }, { + routes: { + prefix: '/hoodie/account' + } + }], [{ register: require('hoodie-server-store'), - options: _.defaults({prefix: '/hoodie/store'}, defaultOpts) - })) + options: { + couchdb: 'http://localhost:5984' + } + }, { + routes: { + prefix: '/hoodie/store' + } + }]]))) }, callback) } diff --git a/lib/index.js b/lib/index.js index 2f7c4bb..282cf73 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,4 @@ +var async = require('async') var hapi = require('hapi') var log = require('npmlog') @@ -43,11 +44,20 @@ module.exports = function (options, callback) { /* istanbul ignore next */ if (err) return callback(err) - server.register(plugins, function (err) { - /* istanbul ignore next */ - if (err) return callback(err) + var registerFunctions = plugins.map(function (config) { + if (Array.isArray(config)) { + return server.register.bind(server, config[0], config[1]) + } + + return server.register.bind(server, config) + }) + + async.series(registerFunctions, function (error) { + if (error) { + return callback(error) + } - log.verbose('hapi', 'Registerd internal plugins') + log.verbose('hapi', 'Registered internal plugins') callback(null, server, config) }) })