The environment control interceptor is your friend here but the
default that ships with ColdBox is based on request URLs rather than
hostnames.
Here's a version that uses the native hostname:
component extends="coldbox.system.interceptors.EnvironmentControl" {
public string function detectEnvironment( array environmentsArray ) {
// the environment cannot change during the application's life so we
can cache this:
if ( structKeyExists( variables, 'selectedEnvironment' ) ) {
setSetting( 'ENVIRONMENT', variables.selectedEnvironment );
return variables.selectedEnvironment;
}
var myHost = createObject( 'java', 'java.net.InetAddress'
).getLocalHost().getHostName();
// force development unless we find a match for production:
var environment = 'development';
var logger = logbox.getLogger( this );
logger.debug( 'myHost=' & myHost );
for ( var i = 1; i <= arrayLen( arguments.environmentsArray ); ++i ) {
var hostPatterns = trim( arguments.environmentsArray[ i
].XMLAttributes.hosts );
for ( var j = 1; j <= listLen( hostPatterns ); ++j ) {
if ( REFind( listGetAt ( hostPatterns, j ), myHost ) != 0 ){
environment = trim( arguments.environmentsArray[ i ].XMLAttributes.name );
// update the ColdBox ENVIRONMENT setting:
setSetting( 'ENVIRONMENT', environment );
logger.debug( 'Environment ' & environment & ' selected.' );
if ( find( 'development', environment ) == 0 ) {
var cats = logBox.getConfig().getAllCategories();
var cat = 0;
for ( cat in cats ) {
if ( cats[ cat ].levelMax > logBox.logLevels.INFO ) {
logger.debug( 'Non-Development: reset levelMax for ' & cats[
cat ].name );
cats[ cat ].levelMax = logBox.logLevels.INFO;
}
}
}
variables.selectedEnvironment = environment;
return environment;
}
}
}
// update the ColdBox ENVIRONMENT setting:
setSetting( 'ENVIRONMENT', environment );
logger.debug( 'Environment ' & environment & ' defaulted.' );
variables.selectedEnvironment = environment;
return environment;
}
}
Here's how to declare it in coldbox.xml:
<!-- USE ENVIRONMENT CONTROL -->
<Interceptor class="ws.model.interceptors.EnvironmentControlByHost">
<Property name='configFile'>config/environments.xml.cfm</Property>
</Interceptor>
Here's a fragment of the environments.xml file:
<environment name="development-charlie" urls="unused"
hosts="charlie-griefers,mycingular.net">
<!-- where email bounces should go to -->
<Setting name="BounceEmail" value="charlie@....com" />
...
</environment>
<environment name="development-mark" urls="unused" hosts="markdrew">
<!-- where email bounces should go to -->
<Setting name="BounceEmail" value="mark@....com" />
...
<IOC>
<Framework type="coldspring" reload="false"
objectCaching="false">config/ColdSpring.xml.cfm</Framework>
</IOC>
</environment>
<environment name="development-sean" urls="unused"
hosts="Sean-Corfields,scorfield,myvzw.com">
<!-- where email bounces should go to -->
<Setting name="BounceEmail" value="sean@....org" />
...
<!-- testing settings -->
<Setting name="DebugMode" value="true" />
</environment>
Just find some string that's unique for each machine. My entry has
parts of my desktop and my laptop machine names. The .com / .net stuff
in Charlie's and mine are so it works properly if we're connected via
our broadband cards - fortunately we're on different ISPs and we're
the only two devs who work on the road!
HTH,
Sean