From b5cc7b1ff09d391fb77b76f70a3f75c1f7a4607b Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Fri, 25 Jan 2013 12:29:08 -0600 Subject: [PATCH 1/7] Replacing ext.onUnknown with a notFound handler --- examples/extensions.js | 11 ----- lib/notFound.js | 16 +++++++ lib/request.js | 52 --------------------- lib/route.js | 14 +++--- lib/server.js | 24 +++++++--- test/integration/notFound.js | 87 ++++++++++++++++++++++++++++++++++++ test/integration/request.js | 12 ++--- test/unit/request.js | 7 +-- 8 files changed, 137 insertions(+), 86 deletions(-) create mode 100644 lib/notFound.js create mode 100644 test/integration/notFound.js diff --git a/examples/extensions.js b/examples/extensions.js index 0d118bd5c..2cfbe21dd 100755 --- a/examples/extensions.js +++ b/examples/extensions.js @@ -49,13 +49,6 @@ internals.onPostRoute = function (request, next) { }; -internals.onUnknownRoute = function (request) { - - Hapi.Log.event('onUnknownRoute'); - request.reply(Hapi.Error.notFound()); -}; - - internals.main = function () { var config = { @@ -65,10 +58,6 @@ internals.main = function () { internals.onPreHandler2], // After validation and body parsing, before route handler onPostHandler: internals.onPostHandler, // After route handler returns, before setting response onPostRoute: internals.onPostRoute, // After response sent - - // Overrides hapi's default handler for unknown route. Cannot be an array! - - onUnknownRoute: internals.onUnknownRoute } }; diff --git a/lib/notFound.js b/lib/notFound.js new file mode 100644 index 000000000..9a90f5f8e --- /dev/null +++ b/lib/notFound.js @@ -0,0 +1,16 @@ +// Load modules + +var Err = require('./error'); + +// Declare internals + +var internals = {}; + + +exports.handler = function (route) { + + return function (request) { + + return request.reply(Err.notFound('No such path or method ' + request.path)); + }; +}; \ No newline at end of file diff --git a/lib/request.js b/lib/request.js index cd01c9ffb..87f0d175c 100755 --- a/lib/request.js +++ b/lib/request.js @@ -227,11 +227,6 @@ internals.Request.prototype._execute = function (route) { var self = this; - if (!route) { - // 404 - return this._unknown(); - } - this._route = route; // Handler wrappers @@ -398,53 +393,6 @@ internals.Request.prototype._undecorate = function () { }; -internals.Request.prototype._unknown = function () { - - var self = this; - - if (!this.server.settings.ext.onUnknownRoute) { - - // No extension handler - - this._response = Err.notFound('No such path or method ' + this.path); - this._respond(); - this._wagTail(); - return; - } - - // Decorate request with extension helpers - - this._decorate(function (response) { - - // Called when reply...send() or reply() is called - - self._response = response; - self._respond(); - self._wagTail(); - }); - - // Unknown-specific chain finalizer - - this.reply.close = function () { - - self._undecorate(); - - self.log(['http', 'response', 'ext']); - - if (!self._isResponded) { - self.server.emit('response', self); - self._isResponded = true; - } - - self._wagTail(); - }; - - // Extension handler - - this.server.settings.ext.onUnknownRoute(this); -}; - - internals.Request.prototype._prerequisites = function (next) { var self = this; diff --git a/lib/route.js b/lib/route.js index 77bb4e0fc..c24d5c30a 100755 --- a/lib/route.js +++ b/lib/route.js @@ -1,11 +1,12 @@ // Load modules -var Auth = require('./auth'); var Catbox = require('catbox'); -var Utils = require('./utils'); -var Proxy = require('./proxy'); -var Files = require('./files'); +var Auth = require('./auth'); var Docs = require('./docs'); +var Files = require('./files'); +var NotFound = require('./notFound'); +var Proxy = require('./proxy'); +var Utils = require('./utils'); var Views = require('./views'); @@ -37,7 +38,7 @@ exports = module.exports = internals.Route = function (options, server) { Utils.assert(!!settings.handler ^ !!this.config.handler, 'Handler must appear once and only once'); // XOR this.config.handler = this.config.handler || settings.handler; - Utils.assert((typeof this.config.handler === 'function') ^ !!this.config.handler.proxy ^ !!this.config.handler.file ^ !!this.config.handler.directory ^ !!this.config.handler.docs ^ !!this.config.handler.view, 'Handler must be a function or an object with a proxy, docs, file, directory or view'); + Utils.assert((typeof this.config.handler === 'function') ^ !!this.config.handler.proxy ^ !!this.config.handler.file ^ !!this.config.handler.directory ^ !!this.config.handler.docs ^ !!this.config.handler.view ^ (this.config.handler === 'notFound'), 'Handler must be a function or equal notFound or be an object with a proxy, docs, file, directory, or view'); // Payload configuration ('stream', 'raw', 'parse') // Default is 'parse' for POST and PUT otherwise 'stream' @@ -134,6 +135,9 @@ exports = module.exports = internals.Route = function (options, server) { this.config.handler = Views.handler(this, this.config.handler.view); } } + else if (this.config.handler === 'notFound') { + this.config.handler = NotFound.handler(this); + } return this; }; diff --git a/lib/server.js b/lib/server.js index 9b8afd8bd..a43aad75b 100755 --- a/lib/server.js +++ b/lib/server.js @@ -70,9 +70,6 @@ module.exports = internals.Server = function (/* host, port, options */) { this.settings.debug = Utils.applyToDefaults(Defaults.debug, this.settings.debug); this.settings.docs = Utils.applyToDefaults(Defaults.docs, this.settings.docs); - // Validate configuration - - Utils.assert(!this.settings.ext.onUnknownRoute || this.settings.ext.onUnknownRoute instanceof Array === false, 'ext.onUnknownRoute cannot be an array'); // Initialize process monitoring @@ -85,6 +82,7 @@ module.exports = internals.Server = function (/* host, port, options */) { this._routes = {}; this.routeDefaults = null; + this.setNotFound({ handler: 'notFound', docs: false }); // Initialize Views @@ -200,7 +198,7 @@ internals.Server.prototype._dispatch = function (options) { } } - request._execute(); + request._execute(self._routes['*']); }); }; }; @@ -240,10 +238,12 @@ internals.Server.prototype._routeTable = function () { Object.keys(this._routes).forEach(function (method) { - self._routes[method].forEach(function (route) { + if (method !== '*') { + self._routes[method].forEach(function (route) { - flattenedRoutes.push(route); - }); + flattenedRoutes.push(route); + }); + } }); return flattenedRoutes; @@ -300,6 +300,16 @@ internals.Server.prototype.setRoutesDefaults = function (config) { }; +// Set notFound route for the server + +internals.Server.prototype.setNotFound = function (routeConfig) { + + Utils.assert(routeConfig && routeConfig.handler, 'routeConfig must exist and provide a handler'); + + this._routes['*'] = new Route({ method: '*', path: '/{p*}', config: routeConfig }, this); +}; + + // Add server route internals.Server.prototype.addRoute = function (options) { diff --git a/test/integration/notFound.js b/test/integration/notFound.js new file mode 100644 index 000000000..96a3cece3 --- /dev/null +++ b/test/integration/notFound.js @@ -0,0 +1,87 @@ +// Load modules + +var Chai = require('chai'); +var Hapi = require('../helpers'); + + +// Declare internals + +var internals = {}; + + +// Test shortcuts + +var expect = Chai.expect; + + +describe('NotFound', function () { + + describe('using default settings', function () { + + var server = new Hapi.Server(0); + + it('returns 404 when making a request to a route that doesn\'t exist', function (done) { + + server.inject({ method: 'GET', url: '/nope' }, function (res) { + + expect(res.statusCode).to.equal(404); + done(); + }); + }); + }); + + describe('using notFound routes', function () { + + var server = new Hapi.Server(0); + server.addRoute({ method: 'GET', path: '/exists/not', handler: 'notFound' }); + server.addRoute({ method: 'GET', path: '/exists/{p*}', handler: function (request) { request.reply('OK'); } }); + + it('returns 404 when making a request to a notFound route', function (done) { + + server.inject({ method: 'GET', url: '/exists/not' }, function (res) { + + expect(res.statusCode).to.equal(404); + done(); + }); + }); + + it('returns 200 when making a request to an existing route', function (done) { + + server.inject({ method: 'GET', url: '/exists/ok' }, function (res) { + + expect(res.statusCode).to.equal(200); + done(); + }); + }); + }); + + describe('can override the server notFound route', function () { + + var server = new Hapi.Server(0); + server.addRoute({ method: 'GET', path: '/exists/{p*}', handler: function (request) { request.reply('OK'); } }); + + server.setNotFound({ handler: function (request) { + + request.reply(Hapi.Error.notFound('These these aren\'t the pages you\'re looking for.')); + }}); + + it('returns custom response when requesting a route that doesn\'t exist', function (done) { + + server.inject({ method: 'GET', url: '/page' }, function (res) { + + expect(res.statusCode).to.equal(404); + expect(res.result.message).to.equal('These these aren\'t the pages you\'re looking for.'); + done(); + }); + }); + + it('returns 200 when making a request to an existing route', function (done) { + + server.inject({ method: 'GET', url: '/exists/ok' }, function (res) { + + expect(res.statusCode).to.equal(200); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/integration/request.js b/test/integration/request.js index cb70caba3..6b828fb80 100755 --- a/test/integration/request.js +++ b/test/integration/request.js @@ -49,22 +49,22 @@ describe('Request', function () { request.reply('unknown-reply'); } else if (request.path === '/unknown/close') { - request.raw.res.writeHead(400, { 'Content-Length': 13 }); - request.raw.res.end('unknown-close'); - request.reply.close(); + request.reply.payload('unknown-close').send(); } else { request.reply('unknown-error'); } }; - var server = new Hapi.Server('0.0.0.0', 0, { ext: { onUnknownRoute: unknownRouteHandler, onPostHandler: postHandler } }); + var server = new Hapi.Server('0.0.0.0', 0, { ext: { onPostHandler: postHandler } }); server.addRoutes([ { method: 'GET', path: '/custom', config: { handler: customErrorHandler } }, { method: 'GET', path: '/tail', config: { handler: tailHandler } }, { method: 'GET', path: '/ext', config: { handler: plainHandler } } ]); + server.setNotFound({ handler: unknownRouteHandler }); + var makeRequest = function (method, path, callback) { var next = function (res) { @@ -135,8 +135,8 @@ describe('Request', function () { makeRequest('GET', '/unknown/close', function (res) { - expect(res.statusCode).to.equal(400); - expect(res.readPayload()).to.equal('unknown-close'); + expect(res.statusCode).to.equal(200); + expect(res.result).to.equal('unknown-close'); done(); }); }); diff --git a/test/unit/request.js b/test/unit/request.js index 2dac5ba96..bb8fbde2d 100755 --- a/test/unit/request.js +++ b/test/unit/request.js @@ -98,14 +98,11 @@ describe('Request', function () { var req = Hapi.Utils.clone(_req); req.pause = function () { }; - var serverModified = Hapi.Utils.clone(server); + var debugServer= new Hapi.Server(0, { debug: { queryKey: 'debug' } }); req.url = 'http://localhost/?debug=test'; - serverModified.settings.debug = { - queryKey: 'debug' - }; - var request = new Request(serverModified, req, _res); + var request = new Request(debugServer, req, _res); expect(request._debug).to.exist; done(); From f42dcf535b7b6fd9c0ebc73f078680e5fad5cf58 Mon Sep 17 00:00:00 2001 From: Wyatt Date: Fri, 25 Jan 2013 12:49:01 -0600 Subject: [PATCH 2/7] Adding notFound documentation --- README.md | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ca17bf0e9..bd954eb48 100755 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ Current version: **0.11.3** - [Router](#router) - [Payload](#payload) - [Extensions](#extensions) - - [Unknown Route](#unknown-route) - [Format](#format) - [Error Format](#error-format) - [Payload Format](#payload-format) @@ -229,52 +228,59 @@ function onRequest(request, next) { } ``` +### Not Found Route #### Unknown Route **hapi** provides a default handler for unknown routes (HTTP 404). If the application needs to override the default handler, it can use the -`ext.onUnknownRoute` server option. The extension function signature is _function (request)_ where: -- _'request'_ is the **hapi** request object. +`notFound` server option. The option should be a route configuration object with a handler property. -When the extension handler is called, the _'request'_ object is decorated as described in [Route Handler](#route-handler) with the following additional method: -- _'reply.close()'_ - returns control over to the server after the application has taken care of responding to the request via the _request.raw.res_ object directly. - -The method **must** return control over to the route using the _reply_ interface described in [Route Handler](#route-handler) or the _'reply.close()'_ method but not both. - -For example, using the _'reply.close()'_ method: +For example, the default notFound route configuration can be set as shown below: ```javascript var Hapi = require('hapi'); var options = { - ext: { - onUnknownRoute: onUnknownRoute + notFound: { + handler: notFoundHandler } }; // Create server -var http = new Hapi.Server('localhost', 8000, options); +var http = new Hapi.Server(8000, options); // Start server http.start(); // 404 handler -function onUnknownRoute(request) { +function notFoundHandler(request) { - request.raw.res.writeHead(404); - request.raw.res.end(); - request.reply.close(); + request.reply(Hapi.Error.notFound('The page was not found')); } ``` -Or using the _'reply(result)'_ method: +The _'notFound'_ route configuration can also be set using the _'setNotFound'_ server method. This method has the same requirements as the _'notFound'_ server configuration. Below is an example creating a server and then setting the _'notFound'_ route configuration. + +For example, the default notFound route configuration can be set as shown below: ```javascript -function onUnknownRoute(request) { +var Hapi = require('hapi'); + + +// Create server +var http = new Hapi.Server(8000); + +// Set the notFound route configuration +http.setNotFound({ handler: notFoundHandler }); - request.reply({ roads: 'ocean' }); +// Start server +http.start(); + +// 404 handler +function notFoundHandler(request) { + + request.reply(Hapi.Error.notFound('The page was not found')); } ``` - ### Format The `format` option provides an extension point for use of custom methods to format error responses or payloads before they are sent back to the client. @@ -1180,6 +1186,14 @@ http.start(); The 'request.log' method is always available. +### Not Found Route Handler + +Whenever a route needs to respond with a simple 404 message use the _'notFound'_ handler. This can be done by simply setting the route _'handler'_ property to the string 'notFound'. Below is an example of a route that responds with a 404. +```javascript +{ method: 'GET', path: '/hideme', handler: 'notFound' } +``` + + ### Query Validation When a request URI includes a query component (the key-value part of the URI between _?_ and _#_), the query is parsed into its individual From 1a42017358b0ba6dc455d31db68eb436ffa51569 Mon Sep 17 00:00:00 2001 From: Wyatt Date: Fri, 25 Jan 2013 12:51:55 -0600 Subject: [PATCH 3/7] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd954eb48..87d71ba83 100755 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Current version: **0.11.3** - [Router](#router) - [Payload](#payload) - [Extensions](#extensions) + - [Not Found](#not-found-route) - [Format](#format) - [Error Format](#error-format) - [Payload Format](#payload-format) @@ -53,6 +54,7 @@ Current version: **0.11.3** - [View](#view) - [Docs](#documentation) - [Request Logging](#request-logging) + - [Not Found](#not-found) - [Query Validation](#query-validation) - [Payload Validation](#payload-validation) - [Path Validation](#path-validation) @@ -230,8 +232,6 @@ function onRequest(request, next) { ### Not Found Route -#### Unknown Route - **hapi** provides a default handler for unknown routes (HTTP 404). If the application needs to override the default handler, it can use the `notFound` server option. The option should be a route configuration object with a handler property. @@ -1186,7 +1186,7 @@ http.start(); The 'request.log' method is always available. -### Not Found Route Handler +### Not Found Whenever a route needs to respond with a simple 404 message use the _'notFound'_ handler. This can be done by simply setting the route _'handler'_ property to the string 'notFound'. Below is an example of a route that responds with a 404. ```javascript From 278552b7a84ca02915c8826f9e4efe4575f9fe61 Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Fri, 25 Jan 2013 12:56:54 -0600 Subject: [PATCH 4/7] Adding server setting for notFound --- lib/server.js | 2 +- test/integration/notFound.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/server.js b/lib/server.js index a43aad75b..62df2f2a6 100755 --- a/lib/server.js +++ b/lib/server.js @@ -82,7 +82,7 @@ module.exports = internals.Server = function (/* host, port, options */) { this._routes = {}; this.routeDefaults = null; - this.setNotFound({ handler: 'notFound', docs: false }); + this.setNotFound(this.settings.notFound || { handler: 'notFound' }); // Initialize Views diff --git a/test/integration/notFound.js b/test/integration/notFound.js index 96a3cece3..7a6a0c534 100644 --- a/test/integration/notFound.js +++ b/test/integration/notFound.js @@ -55,7 +55,7 @@ describe('NotFound', function () { }); }); - describe('can override the server notFound route', function () { + describe('can override the server notFound route with setNotFound', function () { var server = new Hapi.Server(0); server.addRoute({ method: 'GET', path: '/exists/{p*}', handler: function (request) { request.reply('OK'); } }); @@ -84,4 +84,34 @@ describe('NotFound', function () { }); }); }); + + describe('can override the server notFound route with server settings', function () { + + var notFoundHandler = function (request) { + + request.reply(Hapi.Error.notFound('These these aren\'t the pages you\'re looking for.')); + }; + + var server = new Hapi.Server(0, { notFound: { handler: notFoundHandler } }); + server.addRoute({ method: 'GET', path: '/exists/{p*}', handler: function (request) { request.reply('OK'); } }); + + it('returns custom response when requesting a route that doesn\'t exist', function (done) { + + server.inject({ method: 'GET', url: '/page' }, function (res) { + + expect(res.statusCode).to.equal(404); + expect(res.result.message).to.equal('These these aren\'t the pages you\'re looking for.'); + done(); + }); + }); + + it('returns 200 when making a request to an existing route', function (done) { + + server.inject({ method: 'GET', url: '/exists/ok' }, function (res) { + + expect(res.statusCode).to.equal(200); + done(); + }); + }); + }); }); \ No newline at end of file From 5ce0db68d2b80575f2a17030818d0c4e2afb7915 Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Fri, 25 Jan 2013 12:58:46 -0600 Subject: [PATCH 5/7] Removing unknown extension from defaults --- lib/defaults.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/defaults.js b/lib/defaults.js index 3b50c31e6..d0b28b61d 100755 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -77,9 +77,6 @@ exports.server = { onPreHandler: null, // After validation and body parsing, before route handler onPostHandler: null, // After route handler returns, before sending response onPostRoute: null, // After response sent - - // function (request) { request.reply(result); OR request.reply.close(); } - onUnknownRoute: null // Overrides hapi's default handler for unknown route. Cannot be an array! }, // Response formatter From 25190c94937e76e7433b4a2256c9da55eb3d454e Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Fri, 25 Jan 2013 12:59:14 -0600 Subject: [PATCH 6/7] Small tweak --- lib/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/defaults.js b/lib/defaults.js index d0b28b61d..85c1cd482 100755 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -76,7 +76,7 @@ exports.server = { onRequest: null, // New request, before handing over to the router (allows changes to the request method, url, etc.) onPreHandler: null, // After validation and body parsing, before route handler onPostHandler: null, // After route handler returns, before sending response - onPostRoute: null, // After response sent + onPostRoute: null // After response sent }, // Response formatter From ac26631af052c9e1a95c334f8f6a5882623abaec Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Fri, 25 Jan 2013 16:58:39 -0600 Subject: [PATCH 7/7] Removing server option for notFound --- README.md | 81 +++++++++++++----------------------- lib/server.js | 2 +- test/integration/notFound.js | 30 ------------- 3 files changed, 31 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 87d71ba83..610935305 100755 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ Current version: **0.11.3** - [Router](#router) - [Payload](#payload) - [Extensions](#extensions) - - [Not Found](#not-found-route) - [Format](#format) - [Error Format](#error-format) - [Payload Format](#payload-format) @@ -40,6 +39,8 @@ Current version: **0.11.3** - [Timeout](#timeout)

- [**Server Events**](#server-events) +

+ - [**Server Route Not Found](#not-found)

- [**Route Configuration**](#route-configuration) - [Configuration options](#configuration-options) @@ -230,56 +231,6 @@ function onRequest(request, next) { } ``` -### Not Found Route - -**hapi** provides a default handler for unknown routes (HTTP 404). If the application needs to override the default handler, it can use the -`notFound` server option. The option should be a route configuration object with a handler property. - -For example, the default notFound route configuration can be set as shown below: -```javascript -var Hapi = require('hapi'); - -var options = { - notFound: { - handler: notFoundHandler - } -}; - -// Create server -var http = new Hapi.Server(8000, options); - -// Start server -http.start(); - -// 404 handler -function notFoundHandler(request) { - - request.reply(Hapi.Error.notFound('The page was not found')); -} -``` - -The _'notFound'_ route configuration can also be set using the _'setNotFound'_ server method. This method has the same requirements as the _'notFound'_ server configuration. Below is an example creating a server and then setting the _'notFound'_ route configuration. - -For example, the default notFound route configuration can be set as shown below: -```javascript -var Hapi = require('hapi'); - - -// Create server -var http = new Hapi.Server(8000); - -// Set the notFound route configuration -http.setNotFound({ handler: notFoundHandler }); - -// Start server -http.start(); - -// 404 handler -function notFoundHandler(request) { - - request.reply(Hapi.Error.notFound('The page was not found')); -} -``` ### Format @@ -511,6 +462,34 @@ The server object emits the following events: - _'tail'_ - emitted when a request finished processing, including any registered tails as described in [Request Tails](#request-tails). +## Not Found + +**hapi** provides a default handler for unknown routes (HTTP 404). If the application needs to override the default handler, it can use the +`setNotFound` server method. The method takes a route configuration object with a handler property. + +Below is an example creating a server and then setting the _'notFound'_ route configuration. + +For example, the default notFound route configuration can be set as shown below: +```javascript +var Hapi = require('hapi'); + +// Create server +var http = new Hapi.Server(8000); + +// Set the notFound route configuration +http.setNotFound({ handler: notFoundHandler }); + +// Start server +http.start(); + +// 404 handler +function notFoundHandler(request) { + + request.reply(Hapi.Error.notFound('The page was not found')); +} +``` + + ## Route Configuration **hapi** was designed to move as much logic as possible from the route handler to the route configuration. The goal is to provide a simple diff --git a/lib/server.js b/lib/server.js index 62df2f2a6..39a6dbfef 100755 --- a/lib/server.js +++ b/lib/server.js @@ -82,7 +82,7 @@ module.exports = internals.Server = function (/* host, port, options */) { this._routes = {}; this.routeDefaults = null; - this.setNotFound(this.settings.notFound || { handler: 'notFound' }); + this.setNotFound({ handler: 'notFound' }); // Initialize Views diff --git a/test/integration/notFound.js b/test/integration/notFound.js index 7a6a0c534..f2ff7e7e3 100644 --- a/test/integration/notFound.js +++ b/test/integration/notFound.js @@ -84,34 +84,4 @@ describe('NotFound', function () { }); }); }); - - describe('can override the server notFound route with server settings', function () { - - var notFoundHandler = function (request) { - - request.reply(Hapi.Error.notFound('These these aren\'t the pages you\'re looking for.')); - }; - - var server = new Hapi.Server(0, { notFound: { handler: notFoundHandler } }); - server.addRoute({ method: 'GET', path: '/exists/{p*}', handler: function (request) { request.reply('OK'); } }); - - it('returns custom response when requesting a route that doesn\'t exist', function (done) { - - server.inject({ method: 'GET', url: '/page' }, function (res) { - - expect(res.statusCode).to.equal(404); - expect(res.result.message).to.equal('These these aren\'t the pages you\'re looking for.'); - done(); - }); - }); - - it('returns 200 when making a request to an existing route', function (done) { - - server.inject({ method: 'GET', url: '/exists/ok' }, function (res) { - - expect(res.statusCode).to.equal(200); - done(); - }); - }); - }); }); \ No newline at end of file