Comparing version 3.0.0 to 3.1.0
43
API.md
@@ -6,3 +6,3 @@ | ||
### `compose(manifest, [options], callback)` | ||
### `compose(manifest, [options], [callback])` | ||
@@ -29,2 +29,4 @@ Composes a hapi server object where: | ||
If no `callback` is provided, a `Promise` object is returned where the value passed to the Promise resolve handler is the `server` object and the value passed to the Promise reject handler is the error response if a failure occurred. | ||
### Notes | ||
@@ -37,2 +39,4 @@ | ||
```javascript | ||
'use strict'; | ||
const Glue = require('glue'); | ||
@@ -105,16 +109,15 @@ | ||
```javascript | ||
const server = Hapi.Server({cache: [{engine: require('redis')}]}); | ||
server.connection({ | ||
port: 8000, | ||
labels: ['web'] | ||
}); | ||
server.connection({ | ||
port: 8001, | ||
labels: ['admin'] | ||
}); | ||
let plugin, pluginPath, pluginOptions, registerOptions; | ||
'use strict'; | ||
const server = Hapi.Server({ cache: [{ engine: require('redis') }] }); | ||
server.connection({ port: 8000, labels: ['web'] }); | ||
server.connection({ port: 8001, labels: ['admin'] }); | ||
let plugin; | ||
let pluginPath; | ||
let pluginOptions; | ||
let registerOptions; | ||
pluginPath = Path.join(__dirname, './assets'); | ||
pluginOptions = {uglify: true}; | ||
plugin = {register: require(pluginPath), options: pluginOptions}; | ||
registerOptions = {}; | ||
pluginOptions = { uglify: true }; | ||
plugin = { register: require(pluginPath), options: pluginOptions }; | ||
registerOptions = { }; | ||
server.register(plugin, registerOptions, (err) => { | ||
@@ -126,5 +129,5 @@ | ||
pluginPath = Path.join(__dirname, './ui-user'); | ||
pluginOptions = {}; | ||
plugin = {register: require(pluginPath), options: pluginOptions}; | ||
registerOptions = {select: ['web']}; | ||
pluginOptions = { }; | ||
plugin = { register: require(pluginPath), options: pluginOptions }; | ||
registerOptions = { select: ['web'] }; | ||
server.register(plugin, registerOptions, (err) => { | ||
@@ -136,5 +139,5 @@ | ||
pluginPath = Path.join(__dirname, './ui-admin'); | ||
pluginOptions = {sessiontime: 500}; | ||
plugin = {register: require(pluginPath), options: pluginOptions}; | ||
registerOptions = {select: ['admin'], routes: {prefix: '/admin'}}; | ||
pluginOptions = { sessiontime: 500 }; | ||
plugin = { register: require(pluginPath), options: pluginOptions }; | ||
registerOptions = { select: ['admin'], routes: { prefix: '/admin' } }; | ||
server.register(plugin, registerOptions, (err) => { | ||
@@ -141,0 +144,0 @@ |
@@ -36,11 +36,28 @@ 'use strict'; | ||
exports.compose = function (manifest /*, [options], callback */) { | ||
exports.compose = function (manifest /*, [options], [callback] */) { | ||
const options = arguments.length === 2 ? {} : arguments[1]; | ||
const callback = arguments.length === 2 ? arguments[1] : arguments[2]; | ||
Hoek.assert(arguments.length <= 3, 'Invalid number of arguments'); | ||
Hoek.assert(typeof callback === 'function', 'Invalid callback'); | ||
const options = arguments.length === 1 || typeof arguments[1] === 'function' ? {} : arguments[1]; | ||
const callback = typeof arguments[arguments.length - 1] === 'function' ? arguments[arguments.length - 1] : null; | ||
Joi.assert(options, internals.schema.options, 'Invalid options'); | ||
Joi.assert(manifest, internals.schema.manifest, 'Invalid manifest'); | ||
// Return Promise if no callback provided | ||
if (!callback) { | ||
return new Promise((resolve, reject) => { | ||
exports.compose(manifest, options, (err, server) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
return resolve(server); | ||
}); | ||
}); | ||
} | ||
// Create server | ||
@@ -47,0 +64,0 @@ |
{ | ||
"name": "glue", | ||
"description": "Server composer for hapi.js", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"repository": { | ||
@@ -21,4 +21,3 @@ "type": "git", | ||
"dependencies": { | ||
"boom": "3.x.x", | ||
"hapi": "11.x.x", | ||
"hapi": "11.x.x || 12.x.x", | ||
"hoek": "3.x.x", | ||
@@ -31,3 +30,3 @@ "items": "2.x.x", | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
"lab": "8.x.x" | ||
}, | ||
@@ -34,0 +33,0 @@ "scripts": { |
@@ -27,2 +27,2 @@ ## glue | ||
Glue currently supports hapi **11**. | ||
Glue currently supports hapi **11** and **12**. |
@@ -36,2 +36,60 @@ 'use strict'; | ||
it('returns a promise if no options and no callback is provided', (done) => { | ||
const manifest = {}; | ||
Glue.compose(manifest).then((server) => { | ||
expect(server.connections).length(1); | ||
done(); | ||
}); | ||
}); | ||
it('returns a promise if no callback is provided', (done) => { | ||
const manifest = {}; | ||
const options = {}; | ||
Glue.compose(manifest, options).then((server) => { | ||
expect(server.connections).length(1); | ||
done(); | ||
}); | ||
}); | ||
it('rejects a promise if an error is thrown', (done) => { | ||
const manifest = { | ||
registrations: [ | ||
{ | ||
plugin: './invalid-plugin' | ||
} | ||
] | ||
}; | ||
Glue.compose(manifest).catch((err) => { | ||
expect(err).to.exist(); | ||
expect(err.code).to.equal('MODULE_NOT_FOUND'); | ||
done(); | ||
}); | ||
}); | ||
it('rejects a promise if an error is returned', (done) => { | ||
const manifest = {}; | ||
const options = { | ||
preRegister: function (server, callback) { | ||
callback({ error: 'failed' }); | ||
} | ||
}; | ||
Glue.compose(manifest, options).then(null, (err) => { | ||
expect(err).to.exist(); | ||
done(); | ||
}); | ||
}); | ||
it('composes a server with server.cache as a string', (done) => { | ||
@@ -421,13 +479,2 @@ | ||
it('throws on callback not a function', (done) => { | ||
const manifest = {}; | ||
expect(() => { | ||
Glue.compose(manifest, 'hello'); | ||
}).to.throw(/Invalid callback/); | ||
done(); | ||
}); | ||
it('throws on invalid manifest (not an object)', (done) => { | ||
@@ -434,0 +481,0 @@ |
Sorry, the diff of this file is not supported yet
58912
4
550
+ Addedhapi@12.1.0(transitive)
+ Addedshot@3.5.2(transitive)
+ Addedsubtext@4.4.1(transitive)
+ Addedwreck@12.6.2(transitive)
- Removedboom@3.x.x
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhapi@11.1.4(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedqs@6.14.0(transitive)
- Removedshot@2.0.1(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedsubtext@3.0.2(transitive)
- Removedwreck@7.2.1(transitive)
Updatedhapi@11.x.x || 12.x.x