Clean up code and syntax issues.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Blake Embrey · committed by Blake Embrey · parent 9ae1d0d · Browse files · 3 files·+13 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+13 added−16 removed
- tests:+6 added−7 removed
- other:+7 added−9 removed
Provenance
- Commit
c7e84d8- Tree
f1cc5e2- Author
Blake Embrey <hello@blakeembrey.com>- Committer
Blake Embrey <hello@blakeembrey.com>- Parent
9ae1d0d
3 files changed+13 added−16 removed
modified:lib/router/index.js+5 added-7 removed
168 unmodified lines169 var route = layer.route;170 171 // if final route, then we support options172 if (route) {173- // we don't run any routs with error first173+ // we don't run any routes with error first174 if (err) {175 return next(err);176 }177 140 unmodified lines318 * @api public319 */320 321 proto.use = function(route, fn){322-322 // default route to '/'323 if ('string' != typeof route) {324 fn = route;325 route = '/';9 unmodified lines335 if ('/' == route[route.length - 1]) {336 route = route.slice(0, -1);337 }338 340- var layer = Layer(route, {339+ var layer = new Layer(route, {340 sensitive: this.caseSensitive,341 strict: this.strict,342 end: false343 }, fn);20 unmodified lines364 365 proto.route = function(path){366 var route = new Route(path);367 369- var layer = Layer(path, {368+ var layer = new Layer(path, {369 sensitive: this.caseSensitive,370 strict: this.strict,371 end: true372 }, route.dispatch.bind(route));6 unmodified lines379 380 // create Router#VERB functions381 methods.concat('all').forEach(function(method){382 proto[method] = function(path, fn){384- var self = this;385- self.route(path)[method](fn);386- return self;383+ this.route(path)[method](fn);384+ return this;385 };386 });387 modified:lib/router/route.js+2 added-2 removed
127 unmodified linesExpand all12812913013113213213313413513612 unmodified lines14915015115215315315415515615716 unmodified lines127 unmodified linesExpand all
Route.prototype.all = function(fn){ if (typeof fn !== 'function') { var type = {}.toString.call(fn); var msg = 'Route.use() requires callback functions but got a ' + type; var msg = 'Route.all() requires callback functions but got a ' + type; throw new Error(msg); }
if (!this.stack) {12 unmodified linesmethods.forEach(function(method){ Route.prototype[method] = function(fn){ if (typeof fn !== 'function') { var type = {}.toString.call(fn); var msg = 'Route.use() requires callback functions but got a ' + type; var msg = 'Route.' + method + '() requires callback functions but got a ' + type; throw new Error(msg); }
debug('%s %s', method, this.path);16 unmodified linesmodified:test/Router.js+6 added-7 removed
3 unmodified lines4 , methods = require('methods')5 , assert = require('assert');6 7 describe('Router', function(){8-8 it('should return a function with router methods', function() {9 var router = Router();10 assert(typeof router == 'function');11 4 unmodified lines16 assert(typeof router.handle == 'function');17 assert(typeof router.use == 'function');18 });19 21- it('should support .use of other routers', function(done) {22- var router = Router();23- var another = Router();20+ it('should support .use of other routers', function(done){21+ var router = new Router();22+ var another = new Router();23 25- another.get('/bar', function(req, res) {26- res.done();24+ another.get('/bar', function(req, res){25+ res.end();26 });27 router.use('/foo', another);28 30- router.handle({ url: '/foo/bar', method: 'GET' }, { done: done });29+ router.handle({ url: '/foo/bar', method: 'GET' }, { end: done });30 });31 32 it('should support dynamic routes', function(done){33 var router = new Router();136 unmodified lines