Skip to content

Commit

Permalink
WIP – pass routes prefix as 2nd argument to server.register
Browse files Browse the repository at this point in the history
* * *

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/
  • Loading branch information
gr2m committed Dec 23, 2015
1 parent aa3ae91 commit bcb582c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
33 changes: 19 additions & 14 deletions lib/hapi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var _ = require('lodash')

module.exports = function (config, couchConfig, callback) {
var database = require('./database')(config)
var usersDb = database(couchConfig.authentication_db)
Expand All @@ -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')
Expand All @@ -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)
}
18 changes: 14 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var async = require('async')
var hapi = require('hapi')
var log = require('npmlog')

Expand Down Expand Up @@ -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)
})
})
Expand Down

0 comments on commit bcb582c

Please sign in to comment.