Skip to content

Commit

Permalink
refactor(plugin): pass route options to external plugins only
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jun 13, 2017
1 parent 6f2705e commit fbeef3b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions server/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ function checkModule (modulePath) {

function registerPlugins (server, options, callback) {
var hapiPlugins = [
'inert'
require('inert')
]

var localPlugins = [
'./client',
'./logger',
'./maybe-force-gzip',
'./public'
]
].map(function (pluginPath) {
return {
options: options,
register: require(pluginPath)
}
})

var externalPlugins = options.plugins
.filter(function (pluginPath) {
Expand All @@ -34,24 +39,22 @@ function registerPlugins (server, options, callback) {
.map(function (pluginPath) {
var pkg = require(pluginPath + '/package.json')
var pluginName = pkg.hoodie ? pkg.hoodie.name || pkg.name : pkg.name
var hapiPluginOptions = require(pluginPath + '/hoodie/server')

return {
register: pluginPath + '/hoodie/server',
routes: { prefix: '/hoodie/' + pluginName }
if (!hapiPluginOptions.register) {
hapiPluginOptions = {register: hapiPluginOptions}
}

hapiPluginOptions.options = options
hapiPluginOptions.routes = { prefix: '/hoodie/' + pluginName }

return hapiPluginOptions
})

var plugins = hapiPlugins.concat(localPlugins, externalPlugins)
.map(function (register) {
var path = register.register ? register.register : register
return {
options: options,
register: require(path),
routes: register.routes
}
})

log.silly('hapi', 'Registering internal plugins')
log.silly('hapi', 'Registering plugins')

server.register(plugins, function (error) {
if (error) {
return callback(error)
Expand Down

0 comments on commit fbeef3b

Please sign in to comment.