Hello Caddy community,
I’m working on a project where I need to dynamically add domains to Caddy’s reverse_proxy
block from my Spring Boot backend. Specifically, I want to be able to use an endpoint in my Spring Boot app, let’s call it /addDomain
, to add new domains to Caddy without manually editing the Caddyfile.
I’ve been exploring options like using Caddy’s REST API or constructing a JSON configuration, but I’m not sure of the best approach or the exact steps involved. Could someone please provide guidance or share their experience if they’ve done something similar before?
My goal is to achieve a setup like this in the Caddyfile:
caddyfile
domain1.com, comingdoming.com, other-coming-domain.com {
reverse_proxy localhost:8080
}
I want to be able to programmatically add domains to this block using my Spring Boot backend without having to edit the Caddyfile directly.
Here’s an example JSON configuration I’ve been considering:
json
{
"apps": {
"http": {
"servers": {
"srv0": {
"routes": [
{
"match": {
"host": ["domain1.com", "comingdoming.com", "other-coming-domain.com"]
},
"handle": [
{
"handler": "reverse_proxy",
"upstreams": ["localhost:8080"]
}
]
}
]
}
}
}
}
}
Would this JSON configuration be valid for achieving the reverse proxy setup I described above? Any help or pointers in the right direction would be greatly appreciated. Thanks in advance!