When using `CFConfig` with <ModCFML>, can the web ...
# box-products
r
When using
CFConfig
with ModCFML, can the web context .cfconfig.json file just be the differences wanted between the server context and the particular web context or do that have to be a full overwrite of the config?
For example, the server context .cfconfig has all the general server config like regional > locale but the web context .cfconfig has the DSN’s and mappings etc or does the context .cfconfig have to have all the server config as well? My testing between servers is inconsistent.
b
@richard.herbert Are you asking a question about CFConfig, or just a question about how Lucee works
Generally speaking, Lucee does not require any config that is set in the server context to be present in the web context as well unless you specifically need to override it for that web context to be different than the server context.
Which honestly is the only way that makes sense-- otherwise the web context would be pointless if it was required to duplicate all the config from the server context!
DNSs and mappings are additive
Meaning if there are 2 DNSs in the server level and 2 more in the web leve, you have 4 available
Unless, of course, one of the web ones has the same name as the server one, in which case it overrides
r
Well yes, that has always been my understanding - the web context inherits from the server context. So if I have a web context .cfconfig file, any config in there, however little (say just DSNs and mappings) would be additive or overwrite based on name. Does the addition of ModCFML confuse matters, I assume not. In which case I need to look closer at why this server is not respecting the context specific cfconfig file. Maybe I’ve got my path to the context specific cfconfig file wrong?
b
So if I have a web context .cfconfig file, any config in there, however little (say just DSNs and mappings) would be additive or overwrite based on name.
Again, it depends on whether you're asking a question about how CFConfig imports or how Lucee works.
There are two distinct phases here I want to make sure we differentitate • The CommandBox startup before Lucee is running where CFConfig writes to XML files on disk that Lucee will use later • The Lucee server at runtime that reads those XML files and then does things with them to create its settings in memory
r
it depends on whether you’re asking a question about how CFConfig imports or how Lucee works.
I guess my better question is, how does CFConfig control the Lucee configuration? From your two phases, CommandBox reads the cfconfig at startup and writes the XML that Lucee then reads in when it starts up. So on the first round, CommandBox then Lucee, Lucee will reflect the cfconfig settings. If I then stop Lucee, make a cfconfig file change and start Lucee back up again, I won’t see that change to the cfconfig in the running Lucee. Does that sound right?
b
Well, now you're just asking more questions and I haven't even gotten enough information to answer the existing ones, lol
r
Sorry, I didn’t read your reply as a question 🙂
b
how does CFConfig control the Lucee configuration?
It writes to XML files. CFConfig's import will be a complete override of "complex" things such as DNSs, mail servers, or caches unless you've used the
--append
flag in which case it isn't
. If I then stop Lucee, make a cfconfig file change and start Lucee back up again, I won’t see that change to the cfconfig in the running Lucee. Does that sound right?
No, that sounds wrong. CFConfig's automatic settings import fires on the
onServerStart
interceptor in CommandBox so it re-imports every time the server starts. I would expect your changes in the JSON files to be represented in the server after starting it.
And that's just talking about the
.cfconfig.json
convention. You can manually import config any time you like with the
Copy code
cfconfig import ...
command. And, depending on your Lucee settings around watching config files for changes, those changes may or may not be immediately picked up by the running server.
So back to the append/overwrite bit. CFConfig does this • Reads the existing XML file into memory • ignores all config not explicitly defined in the JSON. So if there is no
datasources
key in your JSON, CFConfig won't touch the DSNs. • Overwrites (again, unless you've used the
--append
flag) all config which is present in the JSON. So if there IS a
datasources
key in the JSON, then that list of DSNs will be all that is left in the XML once CFConfig is done (all others are removed) • writes the XML file back out
So if you had a JSON file with just a single setting
Copy code
{
  "adminpassword": "foo"
}
then the entire XML file would remain untouched except for the admin password
Does the addition of ModCFML confuse matters, I assume not.
It depends on how easily confused you are 😉 CFConfig has a mechanism to preload any number of lucee web contexts with config, but it's not clear from your question if or how you are using those features. https://cfconfig.ortusbooks.com/using-the-cli/commandbox-server-interceptors/server-start#modcfml-support-for-lucee-contexts
In which case I need to look closer at why this server is not respecting the context specific cfconfig file. Maybe I’ve got my path to the context specific cfconfig file wrong?
Maybe, hard to say without seeing much more of your setup.
I would start by analyzing the console output of the server when starting. CFConfig goes through great lengths to tell you exactly what it's doing.
Do a
--dryRun
start and then confirm if the right config is in the right context from the CLI with the
cfconfig show ...
command
Copy code
cfconfig show fromFormat=luceeweb-/path/to/site1/
cfconfig show fromFormat=luceeweb-/path/to/site2/
r
Okay, a lot of useful knowledge here to unpack…
import will be a complete override of “complex” things such as DNSs
Assumed.
settings import fires on the
onServerStart
That was my assumption but not the experience of one of our devs, hence my attempt to understand the flow.
You can manually import config any time you like
I hadn’t thought about that but I guess that’s just like making changes directly in the Lucee Admin.
So back to the append/overwrite bit. CFConfig does this
That was my assumption.
if you had a JSON file with just a single setting
Also my assumption.
CFConfig has a mechanism to preload any number of lucee web contexts with config
Yes, I can easily get confused 👴 but I did quote that link in my original question and that’s the situation I am in - using ModCFML
start by analyzing the console output of the server when starting
Yes, I did look at that and it looks as I would expect although this is on a colleagues machine but I will look closer. Of course “_it works on my machine_” but there are enough differences to cause some doubt.
Do a
--dryRun
start and then confirm if the right config is in the right context from the CLI with the
cfconfig show ...
command
That’s good idea, I’ll certainly be trying that. Thanks @bdw429s, I’ll work through those ideas tomorrow and report back.
b
👍