Skip to content

Commit

Permalink
Merge pull request hapijs#419 from wpreul/feature/unknown
Browse files Browse the repository at this point in the history
Cleaning up the notFound support
  • Loading branch information
Eran Hammer committed Jan 26, 2013
2 parents 71fbc06 + 64aab52 commit aed392f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Current version: **0.11.3**
<p></p>
- [**Server Events**](#server-events)
<p></p>
- [**Server Route Not Found](#not-found)
- [**Server Route Not Found**](#server-route-not-found)
<p></p>
- [**Route Configuration**](#route-configuration)
- [Configuration options](#configuration-options)
Expand All @@ -55,7 +55,7 @@ Current version: **0.11.3**
- [View](#view)
- [Docs](#documentation)
- [Request Logging](#request-logging)
- [Not Found](#not-found)
- [Not Found](#not-found-handler)
- [Query Validation](#query-validation)
- [Payload Validation](#payload-validation)
- [Path Validation](#path-validation)
Expand Down Expand Up @@ -462,7 +462,7 @@ 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
## Server Route 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.
Expand Down Expand Up @@ -1165,7 +1165,7 @@ http.start();
The 'request.log' method is always available.


### Not Found
### Not Found 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
Expand Down
6 changes: 3 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ internals.Server.prototype._dispatch = function (options) {
}
}

request._execute(self._routes['*']);
request._execute(self._routes.notFound);
});
};
};
Expand Down Expand Up @@ -238,7 +238,7 @@ internals.Server.prototype._routeTable = function () {

Object.keys(this._routes).forEach(function (method) {

if (method !== '*') {
if (method !== 'notFound') {
self._routes[method].forEach(function (route) {

flattenedRoutes.push(route);
Expand Down Expand Up @@ -306,7 +306,7 @@ 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);
this._routes.notFound = new Route({ method: 'notFound', path: '/{p*}', config: routeConfig }, this);
};


Expand Down

0 comments on commit aed392f

Please sign in to comment.