Peter Hoopes
05/29/2023, 5:35 PM.env
file in the root that Commandbox will read an incorporate into Java args. In the Coldbox config.cfc
file there is note in the “Environments” section which says * By default we look in your
.env` file for an environment
key, if not, then we look into this structure or if you have a function called detectEnvironment()
. So is this just a reference to the Coldbox dotenv
module or is it a separate process by which the CF code itself looks for the .env
file and reads in the value?wil-shiftinsert
05/29/2023, 7:51 PMelse if ( len( util.getSystemSetting( "ENVIRONMENT", "" ) ) ) {
configStruct.environment = util.getSystemSetting( "ENVIRONMENT", "" );
}
so it is just calling getSystemSetting which is just checking if this ENVIRONMENT key is present in your environment variables.
There are more ways to load these environment variables. In a commandbox setting dotenv is a popular way, but in some standard hosting setup with apache and lucee we didn’t need the dotenv stuff.
So it is not dependant on dotenv, but in a commandbox env is it certainly an easy way to populate your vars with dotenv in a .env file.
I had quite some issues with other automatic detection methods. Environmental variables is certainly the most reliable way to set the correct production or dev environment.elpete
05/30/2023, 3:41 AMENVIRONMENT
key. CommandBox DotEnv is just one way to supply those.elpete
05/30/2023, 3:41 AMbdw429s
05/30/2023, 6:23 PMbdw429s
05/30/2023, 6:25 PMwe can create a@Peter Hoopes Just a clarification here. Thefile in the root that Commandbox will read an incorporate into Java args..env
.env
file creates environment variables in the server process, which are not the same as Java system properties. Now that said, the commandbox-dotenv module does actually have a legacy behavior which turns
foo=bar
in your .env
file into
-Dfoo=bar
JVM args, but it's behind a flag which is enabled for now, but will be disabled by default at some point in the future. Generally speaking, this doesn't really affect your question since ColdBox's getSystemSetting()
function checks both Java system props and actual environment variables, so it will find it either way.elpete
05/30/2023, 6:43 PMbdw429s
05/30/2023, 6:44 PMbdw429s
05/30/2023, 6:44 PMbdw429s
05/30/2023, 6:46 PMlegacyLoadToServerJVMArgs
setting is still set to true
for now, but that was just going to be until the next major version.elpete
05/30/2023, 7:16 PMJust a clarification here. The .env file creates environment variables in the server process, which are not the same as Java system properties.This here. What is the syntax to create “environment variables in the server process?”
bdw429s
05/30/2023, 7:19 PMbdw429s
05/30/2023, 7:20 PMbdw429s
05/30/2023, 7:21 PMMap
of key/value pairs to the process builder environment (which is a Map itself)elpete
05/30/2023, 7:25 PMbdw429s
05/30/2023, 7:26 PMPeter Hoopes
05/30/2023, 8:04 PM