Skip to content

Commit

Permalink
#163 Add ability to override updateEndpoint setting
Browse files Browse the repository at this point in the history
  • Loading branch information
grantcopley committed Aug 21, 2024
1 parent 298b05f commit 0265789
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions models/CBWIREController.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,13 @@ component singleton {
return requestService.getController().getRenderer().view( argumentCollection=arguments );
}

/**
* Returns the URI endpoint for updating CBWIRE components.
*
* @return string
*/
function getUpdateEndpoint() {
var settings = variables.moduleSettings;
return settings.keyExists( "updateEndpoint") && settings.updateEndpoint.len() ? settings.updateEndpoint : "/cbwire/update";
}
}
2 changes: 1 addition & 1 deletion models/scripts.cfm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<cfoutput>
<!-- CBWIRE SCRIPTS -->
<script src="#getEvent().getModuleRoot( 'cbwire' )#/includes/js/livewire.js?id=239a5c52" data-csrf="#generateCSRFToken()#" data-update-uri="/cbwire/update" data-navigate-once="true"></script>
<script src="#getEvent().getModuleRoot( 'cbwire' )#/includes/js/livewire.js?id=239a5c52" data-csrf="#generateCSRFToken()#" data-update-uri="#getUpdateEndpoint()#" data-navigate-once="true"></script>

<script data-navigate-once="true">
document.addEventListener('livewire:init', () => {
Expand Down
13 changes: 13 additions & 0 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( reMatchNoCase( "CBWIRE Scripts", html ).len() ).toBe( 0 );
} );

it( "should have default updateEndpoint", function() {
var CBWIREController = getInstance( "CBWIREController@cbwire" );
var settings = getInstance( "coldbox:modulesettings:cbwire" );
expect( CBWIREController.getUpdateEndpoint() ).toBe( "/cbwire/update" );
} );

it( "should be able to set updateEndpoint", function() {
var CBWIREController = getInstance( "CBWIREController@cbwire" );
var settings = getInstance( "coldbox:modulesettings:cbwire" );
settings.updateEndpoint = "/index.cfm/cbwire/update";
expect( CBWIREController.getUpdateEndpoint() ).toBe( "/index.cfm/cbwire/update" );
} );

} );

describe("Component.cfc", function() {
Expand Down

0 comments on commit 0265789

Please sign in to comment.