Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions system/web/routing/Router.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1331,13 +1331,20 @@ 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
if ( isSimpleValue( arguments.target ) ) {
args = {
pattern : arguments.pattern,
event : arguments.target,
domain : variables.thisRoute.domain,
verbs : ( variables.thisRoute.keyExists( "verbs" ) ? variables.thisRoute.verbs : "" ),
name : arguments.name
};
Expand All @@ -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
};
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions tests/specs/web/routing/RouterTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
Loading