development vs production fusebox.xml

955 views Asked by At

I'm working on a Fusebox application using Coldfusion, and there is a fusebox.xml file which I'd like to be slightly different on the production server than it is on the development server. Since it appears that this file is just a xml file (ie: I don't think it can be a cfm file), it seems I cannot use some if..else.. logic within fusebox.xml.

So I'm wondering if my assumption above is wrong, or if there is a way to use two files, one for development and one for production?

3

There are 3 answers

0
erikvold On BEST ANSWER

Here is what I did:

<!--For Development Mode =  "development-full-load" , For Production Mode = "production" -->
<if condition="application.applicationname EQ 'xyz-dev'">
    <true>
        <parameter name="mode" value="development-full-load"/>
    </true>
    <false>
        <parameter name="mode" value="production"/>
    </false>
</if>

And obviously the application name is different for the production environment than it is for the development environment.

0
Ciaran Archer On

We don't use Fusebox but we have similar config files that are different from dev to test to production. We just keep all three versions in different directories in the repository and upload the required (production) version to the production servers. Since these files changes infrequently this works for us.

The Fusebox docs don't seem to indicate a way to use a different fusebox.xml but maybe an expert on Fusebox can confirm that.

0
Sergey Galashyn On

In older projects with fusebox.xml we're using another copy of the config called server.xml.

This file is typically out of source control, so it allows easy configuration of application instances. It's structure is pretty the same as fusebox.xml, but includes only attributes which we want to override for current instance, for example datasource or paths:

<?xml version="1.0" encoding="UTF-8"?>
<server>
    <parameter name="mode" value="development-full-load" />
    <parameter name="datasource" value="my_datasource" />
    <parameter name="logRotatePeriod" value="50" />
    <parameter name="someDataPath" value="/home/xxx/yyy/zzz/"/>
</server>

In the fusebox.appinit.cfm or fusebox.init.cfm (depending how frequently this file is changed, or any other reasons) this file is parsed and matching entries in application.fusebox are updated. For example, here's the function for doing this:

<cffunction name="loadLocalConfig" returntype="void" output="false" hint="Read and apply local server.xml configuration">
<cfscript>

    var filesServerPath = application.fusebox.AppRootDirectory & application.fusebox.filesServer;
    var fileParameters = "";
    var oFileParameters = "";
    var aServer = "";
    var i = "";

    if (FileExists(filesServerPath)) {
        // read the contents
        fileParameters = FileRead(filesServerPath);
        // parse XML text into object
        oFileParameters = XMLParse(trim(fileParameters));
        // get fusebox parameters and update their values
        if (StructKeyExists(oFileParameters, "server")){
            aServer = oFileParameters.server.XmlChildren;
            for (i=1; i LTE ArrayLen(aServer); i=i+1) {
                if (aServer[i].XmlName EQ "parameter" AND StructKeyExists(application.fusebox, aServer[i].XmlAttributes.name)) {
                    application.fusebox[aServer[i].XmlAttributes.name] = aServer[i].XmlAttributes.value;
                }
            }
        }
    }

</cfscript>
</cffunction>

BTW, for safety we usually rename them to the fusebox.xml.cfm/server.xml.cfm -- it does not make it CFML file, but protects from direct access without web-server tricks


Also it worth mentioning that in latest (since 2009) Fusebox-based projects we've used Application.cfc for configuration. These are modern-style applications with much better control over the initialization and other stuff available as Application.cfc methods.

With this approach Fusebox is configured as FUSEBOX_PARAMETERS scope. It's even easier to override its values, simply include server.cfm file and put there a chunk of plain CFScript with FUSEBOX_PARAMETERS.datasource = "my_datasource".