smebberson
(Scott Mebberson)
1
Hi,
I’ve been reading over the v2 docs relating to the JSON configuration at JSON Config Structure - Caddy Documentation.
I can’t find anything relating to environment variables support, as available in v1. https://caddyserver.com/v1/docs/caddyfile#env.
Does the JSON configuration support environment variables?
Thanks,
Scott.
1 Like
matt
(Matt Holt)
2
Great question – yes it does! You can use them as described here: Conventions — Caddy Documentation
FYI this is currently in motion, on its way to improvements, so it may not be fully fleshed out yet. e.g. transform a caddyfile with environment variables by sarge · Pull Request #2963 · caddyserver/caddy · GitHub
1 Like
smebberson
(Scott Mebberson)
3
Ah, awesome! Thanks for that.
Is there plans to allow defining environment variables from .env files like it was done for v1? Load environment variables from a .env file · Issue #1941 · caddyserver/caddy · GitHub
Thanks a lot for your outstanding work on Caddy!
That’s a good question. Could you open up an issue for this? Issues · caddyserver/caddy · GitHub
In the meantime, I think you could hack this by using a bash script to set the environment before running Caddy. There’s some good ideas for that here: bash - Set environment variables from file of key/value pairs - Stack Overflow
2 Likes
Sure, will open an issue in some mins
Meanwhile, I was able to workaround this by using:
set -a
source .env
set +a
caddy run
And might also be able to use tools like npm’s dotenv-cli or ruby’s dotenv
2 Likes
system
(system)
Closed
7
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.