So it worked. I added the variables to the environ...
# kobweb
f
So it worked. I added the variables to the environment variables of the run configuration And added all the environment variables to the app globals
Screenshot 2023-12-07 at 11.39.42 PM.png
d
Fantastic! Great, fast work, and a nice way to verify that it's working. For security purposes, I'd recommend filtering out only the env var you need. Otherwise, who knows if you'll accidentally ship a private API key someday that someone put into an env var on a CI.
f
Screenshot 2023-12-07 at 11.40.22 PM.png
d
globals.put(System.getenv("Environment"))
should do it?
f
Yeah, that's true. I would take note of that. Thank you very much
d
Note that convention recommends your env var be ALL_CAPS. And you might want to choose something a bit less generic than "ENVIRONMENT", maybe "XYZ_ENVIRONMENT" where "XYZ" is replaced with the name of your site?
🙌 1
You're very welcome. Keep up the good work!
💪 1
f
This App globals will also work for that docker implementation, I'll just pull them from the
properties
file instead of using the BuildConfig gradle plugin
d
Yes, it should
Not too much magic here -- you're basically informing the Kobweb Application Gradle Plugin which then just hardcodes those values in its generated main.kt file in a way that your site can then query them back later.
(Search your build/ directory for
main.kt
if you want to see it yourself)
f
Awesome, I'll check it out.
c
I'm sorry to ask a question on this stale thread. But I was trying to get an environment variable, but for some reason my run fails because of this error
Copy code
PS C:\Workspace\...\....\....\site> export BASE_URL=<https://127.0.0.1:5432/>; kobweb run
export : The term 'export' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ export BASE_URL=<https://127.0.0.1:5432/>; kobweb run
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (export:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
I found out it happens because I'm on a windows and the
export
command is for linux machines. But when I run
set BASE_URL=<https://127.0.0.1:5432/>; kobweb run
the project won't recognize my environment variable... What could be the issue, any idea?
Sorry, nvm my question as I found I could easily use the command
$env:BASE_URL="<https://127.0.0.1:5432/>"; kobweb run
👍 1