Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(init): move init into their respective modules
BREAKING CHANGE: when `require` ing `hoodie-server` that object exposed an init method before, that could be passed a custom `env_config`. This method is gone. You can only do `require('hoodie-server')(options, cb)` anymore, because hook and plugin initialization now happens on the env_config object that can't be passed from the outside.
- Loading branch information
1 parent
b0ae6be
commit 7921ce5
Showing
4 changed files
with
55 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,44 @@ | ||
var url = require('url') | ||
|
||
var _ = require('lodash') | ||
var async = require('async') | ||
var hapi = require('hapi') | ||
var log = require('npmlog') | ||
|
||
var exports = module.exports = function (options, callback) { | ||
module.exports = function (options, callback) { | ||
'use strict' | ||
|
||
var env_config = require('./config')(options) | ||
|
||
log.level = options.loglevel || 'warn' | ||
|
||
if (!env_config.db.auth) { | ||
return callback(new Error('Authentication details missing from database URL')) | ||
} | ||
var env_config | ||
|
||
exports.init(env_config, callback) | ||
} | ||
|
||
exports.init = function (env_config, callback) { | ||
var async = require('async') | ||
var hapi = require('hapi') | ||
try { | ||
env_config = require('./config')(options) | ||
} catch (err) { | ||
return callback(err) | ||
} | ||
|
||
var options = {} | ||
_.set(options, 'connections.routes.payload.maxBytes', 1048576 * 10) // 10 MB | ||
var serverOptions = {} | ||
_.set(serverOptions, 'connections.routes.payload.maxBytes', 1048576 * 10) // 10 MB | ||
|
||
var server = new hapi.Server(options) | ||
var server = new hapi.Server(serverOptions) | ||
|
||
async.applyEachSeries([ | ||
require('./database/start'), | ||
require('./database/install'), | ||
require('./bundle'), | ||
require('./plugins'), | ||
async.apply(exports.configureServer, server) | ||
require('./plugins') | ||
], env_config, function (err) { | ||
if (err) return callback(err) | ||
|
||
callback(null, server, env_config) | ||
}) | ||
} | ||
|
||
exports.configureServer = function (server, env_config, callback) { | ||
server.connection({ | ||
port: env_config.app.port | ||
}) | ||
server.connection({ | ||
port: env_config.app.port | ||
}) | ||
|
||
log.silly('hapi', 'Registering internal plugins') | ||
var defaultOpts = { | ||
couchdb: url.format(_.omit(env_config.db, 'auth')), | ||
prefix: '/hoodie/account' | ||
} | ||
|
||
var hoodieClient = [{ | ||
register: require('hapi-couchdb-store/lib/routes/couchdb-proxy'), | ||
options: _.defaults({prefix: '/hoodie/store'}, defaultOpts) | ||
}, { | ||
register: require('hapi-couchdb-account/lib/routes/session'), | ||
options: defaultOpts | ||
}, { | ||
register: require('hapi-couchdb-account/lib/routes/account'), | ||
options: defaultOpts | ||
}] | ||
|
||
server.register(require('./hapi')(env_config).concat(hoodieClient), function (err) { | ||
if (err) return callback(err) | ||
log.silly('hapi', 'Registering internal plugins') | ||
server.register(require('./hapi')(env_config), function (err) { | ||
if (err) return callback(err) | ||
|
||
log.verbose('hapi', 'Registerd internal plugins') | ||
server.register(_.compact(_.pluck(_.values(env_config.plugins), 'hooks.hapi')), callback) | ||
log.verbose('hapi', 'Registerd internal plugins') | ||
callback(null, server, env_config) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters