开发与生产 fusionbox.xml

发布于 2024-10-17 04:23:23 字数 394 浏览 6 评论 0原文

我正在使用 Coldfusion 开发 Fusebox 应用程序,并且有一个 fusebox .xml 文件,我希望生产服务器上的文件与开发服务器上的文件略有不同。由于该文件似乎只是一个 xml 文件(即:我不认为它可以是一个 cfm 文件),因此我似乎无法使用某些 fusebox.xml 中的 if..else.. 逻辑。

所以我想知道我的上述假设是否错误,或者是否有一种方法可以使用两个文件,一个用于开发,一个用于生产?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盛夏尉蓝 2024-10-24 04:23:23

在使用 fusebox.xml 的旧项目中,我们使用名为 server.xml 的配置的另一个副本。

该文件通常不受源代码控制,因此可以轻松配置应用程序实例。它的结构与fusebox.xml非常相似,但仅包含我们想要为当前实例覆盖的属性,例如数据源或路径:

<?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>

fusebox.appinit.cfm中> 或 fusebox.init.cfm(取决于此文件更改的频率或任何其他原因)此文件将被解析,并且 application.fusebox 中的匹配条目将被更新。例如,这是执行此操作的函数:

<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>

顺便说一句,为了安全起见,我们通常将它们重命名为 fusebox.xml.cfm/server.xml.cfm ——它不使其成为 CFML 文件,但无需 Web 服务器技巧即可防止直接访问


另外值得一提的是,在最新(自 2009 年以来)基于 Fusebox 的项目中,我们使用 Application.cfc 进行配置。这些是现代风格的应用程序,可以更好地控制初始化和其他可用作 Application.cfc 方法的内容。

通过这种方法,Fusebox 配置为 FUSEBOX_PARAMETERS 范围。覆盖其值甚至更容易,只需包含 server.cfm 文件并使用 FUSEBOX_PARAMETERS.datasource = "my_datasource" 放置一块纯 CFScript。

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".

南城旧梦 2024-10-24 04:23:23

这就是我所做的:

<!--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>

显然,生产环境的应用程序名称与开发环境的应用程序名称不同。

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.

却一份温柔 2024-10-24 04:23:23

我们不使用 Fusebox,但我们有类似的配置文件,这些文件从开发到测试再到生产都不同。我们只需将所有三个版本保存在存储库的不同目录中,并将所需的(生产)版本上传到生产服务器。由于这些文件很少更改,这对我们有用。

Fusebox docs 似乎没有指出使用不同 fusebox.xml 但也许 Fusebox 专家可以确认这一点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文