Skip to content

Commit

Permalink
feat(hapi): enable account component
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/
  • Loading branch information
gr2m committed Dec 23, 2015
1 parent f36d46f commit a6f685d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
67 changes: 33 additions & 34 deletions lib/hapi.js
@@ -1,37 +1,36 @@
// var _ = require('lodash')
// var PouchDB = require('pouchdb')
module.exports = function (config, usersDbName, callback) {
var database = require('./database')(config)
var usersDb = database(usersDbName)

module.exports = function (config, usersDb, callback) {
// var users = new PouchDB(usersDb)
// users.plugin(require('pouchdb-users'))
// users.installUsersBehavior()
// .then(function () {
// var defaultOpts = {
// config: config,
// database: require('./database')(config),
// prefix: '/hoodie/account',
// users: users
// }
//
// // insert below code here
// }, callback)
usersDb.constructor.plugin(require('pouchdb-users'))

callback(null, [
require('inert'),
require('h2o2')
].concat([
require('./static'),
require('./http-log')
].map(function (plugin) {
return {
register: plugin,
options: {config: config}
}
})/*, [{
register: require('@hoodie/server-account-node-sessions'),
options: defaultOpts
}, {
register: require('hoodie-server-store'),
options: _.defaults({prefix: '/hoodie/store'}, defaultOpts)
}]*/))
usersDb.installUsersBehavior().then(function () {
var options = {config, usersDb}

var hapiPlugins = [
require('h2o2'),
require('inert')
]

var localPlugins = [
require('./http-log'),
require('./static')
].map(function (register) { return {options, register} })

var hoodieCorePlugins = [{
plugin: {
options,
register: require('hoodie-server-account')
},
options: {
routes: {prefix: '/hoodie/account'}
}
// }, {
// options,
// register: require('hoodie-server-store'),
// routes: {prefix: '/hoodie/store'}
}]

callback(null, hapiPlugins.concat(localPlugins, hoodieCorePlugins))
}, callback)
}
17 changes: 14 additions & 3 deletions lib/index.js
@@ -1,3 +1,4 @@
var async = require('async')
var hapi = require('hapi')
var log = require('npmlog')

Expand All @@ -15,6 +16,7 @@ module.exports = function (options, callback) {
if (err) return callback(err)

config.db.secret = couchConfig.secret
config.db.admins = couchConfig.admins

server.connection({
host: config.app.hostname,
Expand All @@ -31,9 +33,18 @@ 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 (plugin) {
if (plugin.plugin) {
return server.register.bind(server, plugin.plugin, plugin.options)
}

return server.register.bind(server, plugin)
})

async.series(registerFunctions, function (error) {
if (error) {
return callback(error)
}

log.verbose('hapi', 'Registerd internal plugins')
callback(null, server, config)
Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -6,7 +6,6 @@
"url": "https://github.com/hoodiehq/hoodie-server/issues"
},
"dependencies": {
"@hoodie/server-account-node-sessions": "^1.0.0",
"async": "^1.5.0",
"good": "^6.4.0",
"good-squeeze": "^2.1.0",
Expand All @@ -20,10 +19,9 @@
"memdown": "^1.1.0",
"mkdirp": "^0.5.1",
"my-first-hoodie": "^4.0.0",
"nock": "^3.4.0",
"npmlog": "^2.0.0",
"pouchdb": "^5.1.0",
"pouchdb-users": "^1.0.0",
"pouchdb-users": "^1.0.3",
"randomstring": "^1.1.3",
"request": "^2.65.0",
"require-relative": "^0.8.7"
Expand Down

0 comments on commit a6f685d

Please sign in to comment.