Skip to content

Commit

Permalink
Expose route config in plugin.config. Closes #1767
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jul 16, 2014
1 parent a393307 commit 25ba5e1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
and other essential facilities for building web applications and services. **hapi** enables developers to focus on writing reusable
application logic instead of spending time building infrastructure, without getting in the way.

Current version: **6.1.x** ([release notes](https://github.com/spumko/hapi/issues?labels=release+notes&page=1&state=closed)) [![Build Status](https://secure.travis-ci.org/spumko/hapi.svg)](http://travis-ci.org/spumko/hapi)
Current version: **6.2.x** ([release notes](https://github.com/spumko/hapi/issues?labels=release+notes&page=1&state=closed)) [![Build Status](https://secure.travis-ci.org/spumko/hapi.svg)](http://travis-ci.org/spumko/hapi)

For the latest updates and release information visit [hapijs.com](http://hapijs.com) and follow [@hapijs](https://twitter.com/hapijs) on twitter.

Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Current Documentation
[v6.1.x](https://github.com/spumko/hapi/blob/master/docs/Reference.md)
[v6.2.x](https://github.com/spumko/hapi/blob/master/docs/Reference.md)

## Previous Documentation
[v6.1.x](https://github.com/spumko/hapi/blob/v6.1.0/docs/Reference.md)
[v6.0.x](https://github.com/spumko/hapi/blob/v6.0.0/docs/Reference.md)
[v5.1.x](https://github.com/spumko/hapi/blob/v5.1.0/docs/Reference.md)
[v5.0.x](https://github.com/spumko/hapi/blob/v5.0.0/docs/Reference.md)
Expand Down
16 changes: 15 additions & 1 deletion docs/Reference.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 6.1.x API Reference
# 6.2.x API Reference

- [`Hapi.Server`](#hapiserver)
- [`new Server([host], [port], [options])`](#new-serverhost-port-options)
Expand Down Expand Up @@ -1415,6 +1415,7 @@ Each request object has the following properties:
- `credentials` - the `credential` object received during the authentication process. The presence of an object does not mean
successful authentication.
- `artifacts` - an artifact object received from the authentication strategy and used in authentication-related actions.
- `mode` - the route authentication mode.
- `error` - the authentication error is failed and mode set to `'try'`.
- `session` - an object used by the [`'cookie'` authentication scheme](https://github.com/spumko/hapi-auth-cookie).
- `domain` - the node domain object used to protect against exceptions thrown in extentions, handlers and prerequisites. Can be used to
Expand Down Expand Up @@ -2459,6 +2460,19 @@ exports.register = function (plugin, options, next) {
};
```

#### `plugin.config`

The registration options provided to the `pack.register()` method. Contains:
- `route` - route path prefix and virtual host settings.

```javascript
exports.register = function (plugin, options, next) {

console.log(plugin.config.route.prefix);
next();
};
```

#### `plugin.app`

Provides access to the [common pack application-specific state](#pack-properties).
Expand Down
1 change: 1 addition & 0 deletions lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ internals.Pack.prototype._plugin = function (plugin, registerOptions, state, cal

root.hapi = require('../');
root.version = root.hapi.version;
root.config = { route: env.route };
root.app = self.app;
root.plugins = self.plugins;
root.methods = self._methods.methods;
Expand Down
1 change: 1 addition & 0 deletions test/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ describe('Pack', function () {
var server = new Hapi.Server({ labels: 'test' });
server.pack.register(require('./pack/--test1'), { route: { prefix: '/xyz' } }, function (err) {

expect(server.plugins['--test1'].prefix).to.equal('/xyz');
expect(err).to.not.exist;
server.inject('/xyz/test1', function (res) {

Expand Down
1 change: 1 addition & 0 deletions test/pack/--test1/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports.register = function (plugin, options, next) {
plugin.select('test').route({ path: '/test1', method: 'GET', handler: function (request, reply) { reply('testing123' + ((plugin.app && plugin.app.my) || '')); } });
plugin.expose(internals.math);
plugin.expose('glue', internals.text.glue);
plugin.expose('prefix', plugin.config.route.prefix);

return next();
};
Expand Down

0 comments on commit 25ba5e1

Please sign in to comment.