File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed
Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module.exports = class Layer {
1313 * @param {String= } opts.name route name
1414 * @param {String= } opts.sensitive case sensitive (default: false)
1515 * @param {String= } opts.strict require the trailing slash (default: false)
16+ * @param {Boolean= } opts.pathIsRegexp if true, treat `path` as a regular expression
1617 * @returns {Layer }
1718 * @private
1819 */
@@ -45,6 +46,11 @@ module.exports = class Layer {
4546 if ( this . opts . pathIsRegexp === true ) {
4647 this . regexp = new RegExp ( path ) ;
4748 } else if ( this . path ) {
49+ if ( this . opts . strict === true ) {
50+ // path-to-regexp renamed strict to trailing in v8.1.0
51+ this . opts . trailing = false ;
52+ }
53+
4854 const { regexp : regex , keys } = pathToRegexp ( this . path , this . opts ) ;
4955 this . regexp = regex ;
5056 this . paramNames = keys ;
Original file line number Diff line number Diff line change @@ -481,8 +481,7 @@ class Router {
481481 strict : opts . strict || false ,
482482 prefix : opts . prefix || '' ,
483483 ignoreCaptures : opts . ignoreCaptures ,
484- pathIsRegexp : opts . pathIsRegexp ,
485- trailing : opts . trailing
484+ pathIsRegexp : opts . pathIsRegexp
486485 } ) ;
487486
488487 // if parent prefix exists, add prefix to new route
Original file line number Diff line number Diff line change @@ -1657,7 +1657,7 @@ describe('Router#opts', () => {
16571657 it ( 'responds with 200' , async ( ) => {
16581658 const app = new Koa ( ) ;
16591659 const router = new Router ( {
1660- trailing : false
1660+ strict : true
16611661 } ) ;
16621662 router . get ( '/info' , ( ctx ) => {
16631663 ctx . body = 'hello' ;
@@ -1689,7 +1689,7 @@ describe('Router#opts', () => {
16891689 it ( 'responds with 404 when has a trailing slash' , async ( ) => {
16901690 const app = new Koa ( ) ;
16911691 const router = new Router ( {
1692- trailing : false
1692+ strict : true
16931693 } ) ;
16941694 router . get ( '/info' , ( ctx ) => {
16951695 ctx . body = 'hello' ;
@@ -1704,7 +1704,7 @@ describe('use middleware with opts', () => {
17041704 it ( 'responds with 200' , async ( ) => {
17051705 const app = new Koa ( ) ;
17061706 const router = new Router ( {
1707- trailing : false
1707+ strict : true
17081708 } ) ;
17091709 router . get ( '/info' , ( ctx ) => {
17101710 ctx . body = 'hello' ;
@@ -1720,7 +1720,7 @@ describe('use middleware with opts', () => {
17201720 it ( 'responds with 404 when has a trailing slash' , async ( ) => {
17211721 const app = new Koa ( ) ;
17221722 const router = new Router ( {
1723- trailing : false
1723+ strict : true
17241724 } ) ;
17251725 router . get ( '/info' , ( ctx ) => {
17261726 ctx . body = 'hello' ;
You can’t perform that action at this time.
0 commit comments