Skip to content
Myr

Added DSL level notFound() route support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent a4833e7 · Browse files · 4 files+33 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+33 added−1 removed

  • tests:+11 added−0 removed
  • other:+22 added−1 removed

4 files+33 added−1 removed

modified:lib/express/spec/mocks.js+1 added
modified:lib/express/dsl.js+11 added
129 unmodified lines
130 throw new TypeError('param must pass a function to process "' + key + '"')131 Express.params[key] = fn132}133134/**135 * Register a 404 "Not Found" route.136 *137 * @param {function} fn138 * @api public139 */140141exports.notFound = function(fn) {142 Express.notFound = fn143}144145// --- Routing API146147exports.get = exports.view = route('get')148exports.post = exports.create = route('post')
2 unmodified lines
modified:lib/express/request.js+11 added-1 removed
318 unmodified lines
319 320 /**321 * Halt with 404 Not Found.322 *323 * When a notFound route is defined via the DSL it324 * will then be called regardless or any settings that325 * may be present.326 *327 * notFound(function(){328 * this.halt(404, 'Sorry your page cannot be found')329 * })330 *331 * When "html" is accepted, and "helpful 404" is enabled332 * the not-found page will be shown, otherwise the 333 * request will halt with default 404 status body.334 *
1 unmodified line
336 * @api public337 */338 339 notFound: function() {340 if (Express.notFound)341 Express.notFound.call(this)332 if (this.accepts('html') && set('helpful 404'))342 else if (this.accepts('html') && set('helpful 404'))343 this.halt(404, notFound.render(this))344 else345 this.halt()346 return this
2 unmodified lines
modified:spec/spec.request.js+10 added
303 unmodified lines
304 end305 end306 307 describe '#notFound()'308 describe 'when a notFound route is defined'309 it 'should be called'310 notFound(function(){311 this.halt(404, 'Sorry your page was not found')312 })313 get('/', function(){ this.notFound() })314 get('/').body.should.eql 'Sorry your page was not found'315 end316 end317 318 describe 'when accepting "html"'319 describe 'with "helpful 404" enabled'320 it 'should render the not-found page'321 enable('helpful 404')
32 unmodified lines