diff --git a/system/web/routing/Router.cfc b/system/web/routing/Router.cfc index 3dc81bf46..22b4b8384 100644 --- a/system/web/routing/Router.cfc +++ b/system/web/routing/Router.cfc @@ -1331,6 +1331,12 @@ component if ( !variables.withClosure.isEmpty() ) { processWith( arguments ); } + // route() does not declare domain directly, but group() can add it to the + // arguments collection. Preserve it in the fluent route definition so it + // reaches addRoute() below. + if ( arguments.keyExists( "domain" ) ) { + variables.thisRoute.domain = arguments.domain + } // Prepare Routing Structure var args = {}; // Simple => Event @@ -1338,6 +1344,7 @@ component args = { pattern : arguments.pattern, event : arguments.target, + domain : variables.thisRoute.domain, verbs : ( variables.thisRoute.keyExists( "verbs" ) ? variables.thisRoute.verbs : "" ), name : arguments.name }; @@ -1347,6 +1354,7 @@ component args = { pattern : arguments.pattern, response : arguments.target, + domain : variables.thisRoute.domain, verbs : ( variables.thisRoute.keyExists( "verbs" ) ? variables.thisRoute.verbs : "" ), name : arguments.name }; @@ -1361,6 +1369,11 @@ component if ( !variables.withClosure.isEmpty() ) { processWith( arguments ); } + // Materialize a domain supplied by group() before a fluent terminator + // registers variables.thisRoute. + if ( arguments.keyExists( "domain" ) ) { + variables.thisRoute.domain = arguments.domain + } // Store data and continue variables.thisRoute.pattern = arguments.pattern; diff --git a/tests/specs/web/routing/RouterTest.cfc b/tests/specs/web/routing/RouterTest.cfc index 527f02f9b..1fea34d7b 100644 --- a/tests/specs/web/routing/RouterTest.cfc +++ b/tests/specs/web/routing/RouterTest.cfc @@ -141,6 +141,20 @@ component extends="coldbox.system.testing.BaseModelTest" { expect( routes[ 3 ].pattern ).toBe( "api/users/:id/" ); } ); } ); + + given( "a grouped route with a domain", function(){ + then( "it should preserve the domain for fluent and inline routes", function(){ + router.group( { domain : ":tenant.example.com" }, function(){ + router.route( "/fluent" ).to( "main.fluent" ) + router.route( "/inline", "main.inline" ) + } ) + + var routes = router.getRoutes() + expect( routes ).toHaveLength( 2 ) + expect( routes[ 1 ].domain ).toBe( ":tenant.example.com" ) + expect( routes[ 2 ].domain ).toBe( ":tenant.example.com" ) + } ) + } ) } ); story( "I want to register routes with a toAction() terminator", function(){