Added Route
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent d173eac · Browse files · 2 files·+37 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+37 added−23 removed
- tests:+15 added−4 removed
- other:+22 added−19 removed
Provenance
- Commit
5ec8a9d- Tree
f911e6b- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
d173eac
2 files changed+37 added−23 removed
modified:lib/express/core.js+22 added-19 removed
10 unmodified lines11121314151617181920212223242526272829303132332425262728293031323334353435363738373839404142433940414243444546474810 unmodified lines var plugins = [], routes = [] // --- Route Route = Class({ init: function(method, path, fn, options){ this.method = method this.path = path this.fn = fn } }) /** * Return a routing function for _method_. * * @param {string} method * @return {function} * @api private */ function route(method) { // return function(path, options, callback) { // if (options.constructor == Function) callback = options, options = {} // path = Express.pathToRegexp(Express.normalizePath(path)) // var route = { // keys : Express.regexpKeys, // path : path, // method : method, // options : options, // callback : callback // } // Express.routes.push(route) // Express.hook('onRouteAdded', route) return function(path, options, fn){ if (options instanceof Function) callback = options, options = {} routes.push(new Route(method, path, fn, options)) } // --- Routing API get = view = route('get') post = create = route('post') del = destroy = route('delete') put = update = route('put') } // --- Routing API get = view = route('get') post = create = route('post') del = destroy = route('delete') put = update = route('put') })()No newline at end of fileNo newline at end of filemodified:spec/spec.core.routing.js+15 added-4 removed
3 unmodified lines4567898910111213141516121317181920212223242526273 unmodified lines before method = 'get' end it 'should accept a path with callback function' -{ this[method]('/user', function(){}) }.should.not.throw_error describe 'with callback function' it 'should respond with a body string' this[method]('/user', function(){ return 'test' }) this[method]('/user').body.should.eql 'test' end end it 'should accept options hash and a callback function' -{ this[method]('/user', {}, function(){}) }.should.not.throw_error describe 'with options and callback function' it 'should respond with a body string' this[method]('/user', {}, function(){ return 'test' }) this[method]('/user').body.should.eql 'test' end end endendNo newline at end of fileNo newline at end of file