You can extend your Hoodie app in two ways
- App-specific plugins
- 3rd party plugins
You can extend your Hoodie’s client by creating the file hoodie/client/index.js
in your app’s repository, which should export a Hoodie Client plugin <../api/client/hoodie.html#hoodie-plugin>.
It will dynamically be bundled into your client accessible at the /hoodie/client.js
route.
Example
// /hoodie/client.js
module.exports = function (hoodie) {
hoodie.hello = function (what) {
return Promise.resolve('Hello, ' + (what || 'world') + '!')
}
}
You can extend your Hoodie’s server routes and API by creating hoodie/server/index.js
in your app’s, which should export a hapi plugin.
All server routes defined in the plugin will be prefixed with /hoodie/<app name>
Example
module.exports.register = register
module.exports.register.attributes = {
name: 'hoodie-app-plugin'
}
function register (server, options, next) {
server.route({
method: 'GET',
path: '/api',
handler: function (request, reply) {
reply('Hello, world!')
}
})
next()
}
Hoodie plugins are npm modules. We recommend to prefix your plugin names with
hoodie-plugin-
, but it’s not required. The folder structure is the same as
for app-specific plugins:
The server plugin must be loadable via require('hoodie-plugin-foo/hoodie/server')
.
A Hoodie server plugin is a hapi plugin.
The client plugin must be loadable via require('hoodie-plugin-foo/hoodie/client')
A Hoodie client plugin can be a function or an object,
it will be passed into hoodie.plugin() <../api/client/hoodie.html#hoodie-plugin>
Hoodie plugins can extend the Hoodie client, the Hoodie server and provide a
web UI for /hoodie/<plugin name>. All extension points are optional.
The hoodie/public
folder will be exposed at /hoodie/<plugin name> by the
server if it exists. All server routes will be prefixed with /hoodie/<plugin name>.
<plugin name>
is the name property in your package.json
file, but can be
overridden with the hoodie.name
property.
After installing and adding a Hoodie plugin to your app’s dependencies, you also
have to enable it by adding it to the hoodie.plugins
array in your app’s
package.json file. The names are the npm package names.
The order in which server/client plugins are loaded is
- core modules (account, store, task)
- 3rd party plugins (npm dependencies)
- app plugins
For an example plugin, have a look at Hoodie’s "Hello, world!" plugin .