File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -194,12 +194,18 @@ Route._lastRoute = function () {
194194 * @param {Array } arrayOfNamedMiddleware
195195 * @public
196196 */
197- Route . middlewares = function ( arrayOfNamedMiddleware ) {
197+ Route . middlewares = function ( ) {
198198 let lastRoute = Route . _lastRoute ( )
199+ const arrayOfNamedMiddleware = _ . isArray ( arguments [ 0 ] ) ? arguments [ 0 ] : _ . toArray ( arguments )
199200 helpers . appendMiddleware ( lastRoute , arrayOfNamedMiddleware )
200201 return this
201202}
202203
204+ /**
205+ * @see middlewares
206+ */
207+ Route . middleware = Route . middlewares
208+
203209/**
204210 * @description create a new group of routes
205211 * @method group
Original file line number Diff line number Diff line change @@ -147,6 +147,20 @@ describe('Route',function () {
147147 expect ( routes [ 0 ] . middlewares ) . deep . equal ( [ 'auth' ] )
148148 } )
149149
150+ it ( 'should be able to attach middlewares as multiple parameters' , function ( ) {
151+ Route . any ( '/' , 'SomeController.method' ) . middlewares ( 'auth' , 'web' )
152+ const routes = Route . routes ( )
153+ expect ( routes [ 0 ] ) . to . be . an ( 'object' )
154+ expect ( routes [ 0 ] . middlewares ) . deep . equal ( [ 'auth' , 'web' ] )
155+ } )
156+
157+ it ( 'should be able to attach middlewares using middleware method' , function ( ) {
158+ Route . any ( '/' , 'SomeController.method' ) . middleware ( 'auth' , 'web' )
159+ const routes = Route . routes ( )
160+ expect ( routes [ 0 ] ) . to . be . an ( 'object' )
161+ expect ( routes [ 0 ] . middlewares ) . deep . equal ( [ 'auth' , 'web' ] )
162+ } )
163+
150164 it ( 'should be able to group routes' , function ( ) {
151165 Route . group ( 'admin' , function ( ) {
152166 Route . get ( '/' , 'SomeController.method' )
You can’t perform that action at this time.
0 commit comments