@@ -248,6 +248,7 @@ export function RouteParser() {
248248 const results = [ ] ;
249249 for ( let i = keys . length ; i -- ; ) {
250250 const key = keys [ i ] ;
251+ const route = input [ key ] ;
251252 let pattern ;
252253 // check if origin match for full URL
253254 const re = / : \/ \/ ( [ ^ \/ ] + ) ( \/ .* ) / ;
@@ -274,20 +275,24 @@ export function RouteParser() {
274275 pattern = key ;
275276 }
276277 const parts = parse ( pattern ) ;
277- m = url . match ( new RegExp ( '^' + parts . re + '$' ) ) ;
278- if ( m ) {
279- const matched = m . slice ( 1 ) ;
280- const data = { } ;
281- if ( matched . length ) {
282- parts . names . forEach ( ( name , i ) => {
283- data [ name ] = matched [ i ] ;
278+ route . forEach ( ( { handler, options } ) => {
279+ const caseSensitive = options . caseSensitive ?? true ;
280+ m = url . match ( new RegExp ( '^' + parts . re + '$' , caseSensitive ? '' : 'i' ) ) ;
281+ if ( m ) {
282+ const matched = m . slice ( 1 ) ;
283+ const data = { } ;
284+ if ( matched . length ) {
285+ parts . names . forEach ( ( name , i ) => {
286+ data [ name ] = matched [ i ] ;
287+ } ) ;
288+ }
289+ results . push ( {
290+ pattern : key ,
291+ handler,
292+ data
284293 } ) ;
285294 }
286- results . push ( {
287- pattern : key ,
288- data
289- } ) ;
290- }
295+ } ) ;
291296 }
292297 return results ;
293298 } ;
@@ -470,6 +475,17 @@ export function FileSystem(options) {
470475 }
471476 } ;
472477}
478+ // -----------------------------------------------------------------------------
479+ function pluck ( name ) {
480+ return function ( object ) {
481+ return object [ name ] ;
482+ } ;
483+ }
484+
485+ // -----------------------------------------------------------------------------
486+ function handlers ( arr ) {
487+ return arr . map ( pluck ( 'handler' ) ) ;
488+ }
473489
474490// -----------------------------------------------------------------------------
475491// :: Main Wayne Constructor
@@ -513,7 +529,7 @@ export class Wayne {
513529 if ( ! ( have_wildcard && selected_route ) ) {
514530 selected_route = match [ 0 ] ;
515531 }
516- const fns = [ ...this . _middlewares , ...routes [ selected_route . pattern ] ] ;
532+ const fns = [ ...this . _middlewares , ...handlers ( match ) ] ;
517533 req . params = selected_route . data ;
518534 setTimeout ( function ( ) {
519535 reject ( 'Timeout Error' ) ;
@@ -562,15 +578,15 @@ export class Wayne {
562578 } ) ;
563579 }
564580 method ( method ) {
565- return function ( url , fn ) {
581+ return function ( url , handler , options = { } ) {
566582 if ( ! this . _routes [ method ] ) {
567583 this . _routes [ method ] = { } ;
568584 }
569585 const routes = this . _routes [ method ] ;
570586 if ( ! routes [ url ] ) {
571587 routes [ url ] = [ ] ;
572588 }
573- routes [ url ] . push ( fn ) ;
589+ routes [ url ] . push ( { handler , options } ) ;
574590 return this ;
575591 } ;
576592 }
0 commit comments