[CB7]: Config for Development

In ColdBox 7, we can separate module configurations in their own file in config/modules/{moduleName}.cfc

The config file looks like this:

component{

    function configure(){
        return {
            key : value
        };
    }

}

How can I specify settings for DEVELOPMENT environment? In the component, I added the following, but it doesn’t seem to be working. I tested with cbdebugger module; and I set ENVIRONMENT=development in .env file.

function development() {
        return {
            key : value
        };
}

Any idea? Thanks.

If you dump out getSetting('environment'); what does it show?

The output is “development”.
A workaround (see the code below), inside configure() I have a condition to check the environment. It works, but it’s not elegant.

component{

    function configure(){
        var settings = {
            key : productionValue;
        };

	// This works fine
	if (getSystemSetting( "ENVIRONMENT", "production" ) != "production") {
		settings.key : developmentValue;
	}
    return settings;
    }

}

@lmajano Does the convention work in module-specific config CFCs where a method named after the environment will be executed?

You need to pass in the original config struct as an argument, and then modify the keys directly. Here is an example for cbDebugger module:

	function development( original ){
		original.enabled = true;
		original.debugMode = true;
		original.debugPassword = getSystemSetting( "FW_REINIT_PWD", "" );
		original.cachebox.enabled = true;
		original.cachebox.expanded = false;
		original.async.enabled = false;
		original.requestTracker.coldboxInfo.expanded = true;
		original.requestTracker.executionTimers.expanded = false;
		original.requestTracker.storage = "cachebox";
	 }

At least that’s how I think it works!

1 Like

Thanks a lot. It works. As a side note, the argument is “pass by reference”.