In my server.json, I have the following: ``` "f...
# box-products
s
In my server.json, I have the following:
Copy code
"fusionreactor":{
        "enable":true,
        "licenseKey":"${FR_LICENSEKEY}",
        "debugEnable":false,
        "port":"8089",
        "password":"${LUCEE_ADMIN_PASSWORD}",
        "cloudGroup":"dealstream,${FR_CLOUDGROUP}",
        "defaultApplicationName":"dealstream",
        "licenseDeactivateOnShutdown":true,
        "ChatEnabled":false
    }
I have the various environment variables referenced in that snippet in a .env file in the same app root. But when I do
server start
, none of those .env variables appear to get populated. I have the commandbox-dotenv package installed... am I missing something?
g
if you run
env show
do you see the variables and values you expect?
s
No, I just get
{}
g
when did you add the env variables? If you reload box (type r then enter) or just exit and open back up, can you try that again?
if you add any variables to .env after you have box running, you need to reload box
If you didn't want to add that to server.json, you can also set server variables from .env. For your example, once you get the env vars showing, try adding this and remove the fusionreactor section from server.json
Copy code
BOX_SERVER_FUSIONREACTOR_ENABLE=true
BOX_SERVER_FUSIONREACTOR_LICENSEKEY=***VALUE***
BOX_SERVER_FUSIONREACTOR_DEBUGENABLE=false
BOX_SERVER_FUSIONREACTOR_PORT=8089
BOX_SERVER_FUSIONREACTOR_PASSWORD=***VALUE***
BOX_SERVER_FUSIONREACTOR_CLOUDGROUP=***VALUE***
BOX_SERVER_FUSIONREACTOR_DEFAULTAPPLICATIONNAME=dealstream
BOX_SERVER_FUSIONREACTOR_LICENSEDEACTIVATEONSHUTDOWN=true
BOX_SERVER_FUSIONREACTOR_CHATENABLED=false
and replace the ***VALUE*** with your real values
if you do decide to do that, just add that to your .env.example file too with the license key and password removed (as well as anything else that you don't want checked into version control)
s
My .env looks like so:
Copy code
LUCEE_ADMIN_PASSWORD=
FR_LICENSEKEY=
FR_CLOUDGROUP=
HEALTHCHECK_URI=
APP_ENV=develop
And I also tried:
Copy code
BOX_SERVER_LUCEE_ADMIN_PASSWORD=
BOX_SERVER_FR_LICENSEKEY=
BOX_SERVER_FR_CLOUDGROUP=
BOX_SERVER_HEALTHCHECK_URI=
BOX_SERVER_APP_ENV=develop
Neither seems to do the trick. I run server start and the environment variables are not used. And
env show
returns
{}
Note, I'm trying to use the same .env for my local command box server as I'm using for my production Docker container... also something unique is I have two server.json files - server-frontend.json and server-backoffice.json (to run the app in public vs. admin modes)
I am able to run both servers -
start frontend
and
start backoffice
. But neither one receives the .env variables.
Well, looking through the commandbox-dotenv docs, there is a
dotenvFile
property one can add to server.json. I added
dotenvFile=".env"
and that seems to do the trick. I thought by default commandbox-dotenv would find that file but maybe because I have multiple servers in the same approot, it needs to be specified explicitly. Anyway, thanks for the help.
g
two things, can you confirm that this is installed
box install commandbox-dotenv
also, are you starting the site from within the same directory as the files?
s
yeah, it's installed... see my comment above, we might have cross posted 🙂
g
within CommandBox, make sure you are in the same directory as the .env file, then try
env show
s
I'm guessing it has to do with the fact that I am starting multiple servers from the same directory. Anyway, it's working now! 👍🏻
🤘 1
g
great!
b
@seandaniels If you want to see what the dot env module is doing and why, there is a debug mode you can enable for it
I'm not clear why this isn't working unless you have your web root somewhere other than where the
server.json
lives
You can see it uses
interceptData.serverDetails.serverInfo.webRoot
from the interceptor annnoucement to find the
.env
file
And
.env
is already the default name of the file unless you changed this module setting: https://github.com/commandbox-modules/commandbox-dotenv/blob/master/ModuleConfig.cfc#L5
👍 1
s
.env
is in same webroot as my server.json. Technically there are two server configs though -
server-frontend.json
and
server-backoffice.json
so I can run multiple servers from the same root (front end and our admin console). I'll try enabling the debug mode to see what I can see.
In any event, if I add dotenvFile=".env" to my server configs, it works. So that's an acceptable workaround as far as I am concerned.
OK. I figured this out. At some point in the past I must have changed the
modules.commandbox-dotenv.fileName
to
env.properties
. I don't know when or why. 🤣 But I did a
config show
and sure enough. There ya go...
🤘 1
👍 1