Skip to content

Commit

Permalink
adding app config
Browse files Browse the repository at this point in the history
  • Loading branch information
dbashford committed Jul 11, 2015
1 parent 3d25fc1 commit 953e4a1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ new RouteBuilder()
* [path()](#path)
* [vhost()](#vhost)
* [handler()](#handler)
* [app()](#app)
* [validatePayload()](#validatepayload)
* [validatePayloadKey()](#validatepayloadkey)
* [pre()](#pre)
Expand Down Expand Up @@ -378,6 +379,19 @@ new RouteBuilder().handler(function(request, reply) {
});
```

#### `app`
Sets the `config.app` property.

```javascript

var appConfig = {
foo:"bar",
baz: false
};

new RouteBuilder().app(appConfig).build();
```

#### `validatePayload`
Sets the `config.validate.payload` property of a route configuration.

Expand Down
19 changes: 13 additions & 6 deletions src/configs/misc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
var RouteBuilder = require("../route_builder")
, utils = require("../utils")
;

RouteBuilder.prototype.vhost = function(vhost) {
this.route.vhost = vhost;
RouteBuilder.prototype.vhost = function(_vhost) {
this.route.vhost = _vhost;
return this;
};

RouteBuilder.prototype.path = function(path) {
this.route.path = path;
RouteBuilder.prototype.path = function(_path) {
this.route.path = _path;
return this;
};

RouteBuilder.prototype.handler = function(handler) {
this.route.handler = handler;
RouteBuilder.prototype.handler = function(_handler) {
this.route.handler = _handler;
return this;
};

RouteBuilder.prototype.app = function(_app) {
utils.ensure(this.route, "config");
this.route.config.app = _app;
return this;
};
37 changes: 32 additions & 5 deletions test/integrations/misc_configuration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ describe("vhost configured", function() {
method: 'GET',
url: path,
headers: {
'Set-Cookie': 'mycookie=test',
'Host': 'foo.example.com'
}
}, function(res) {
Expand All @@ -105,14 +104,42 @@ describe("vhost configured", function() {
new TestServer(opts).andTest(function(server, stop) {
server.inject({
method: 'GET',
url: path,
headers: {
'Set-Cookie': 'mycookie=test'
}
url: path
}, function(res) {
expect(res.statusCode).to.equal(404);
stop();
});
});
});
});

describe("config.app", function() {
it("will be passed to the route", function(done) {

var path = "/api/foo";

var appConfig = {
foo: "bar",
baz: false
};

var config = new RouteBuilder()
.get()
.path(path)
.app(appConfig)
.handler(function(request, reply){
reply(request.route.settings.app);
})
.build();

new TestServer({routeConfig: config, done: done}).andTest(function(server, stop) {
server.inject({
method: 'GET',
url: path
}, function(res) {
expect(res.payload).to.equal(JSON.stringify(appConfig))
stop();
});
});
});
});
11 changes: 11 additions & 0 deletions test/units/configs/misc_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ describe("handler tests", function() {
expect(new RouteBuilder().handler(noop).build().handler).to.deep.equal(noop);
done();
});
});

describe("config.app tests", function() {
it("will build a config.app", function(done) {
var appConfig = {
foo: "bar",
baz: false
};
expect(new RouteBuilder().app(appConfig).build().config.app).to.deep.equal(appConfig);
done();
});
});

0 comments on commit 953e4a1

Please sign in to comment.