Plugin or method to create a list of sites

I’m figuring it’s a plugin thing rather than. Core function.

But is anyone aware of a plugin that will read the current running config and present all of the reverse proxied sites.

I’m aware of dashboard apps like dashy, but I’m a bit too lazy for hand configuring things when I already have all my sores proxied via caddy. And seems logical that that would be the best source to feed a dashboard

1 Like

You can ask Caddy for its current configuration using the admin API as follows:

curl "http://localhost:2019/config/"

This is described here

The returned config is in JSON format. You can inspect the JSON for the “host” matchers to identify the configured host names.

3 Likes

Rough example:

{
  local_certs
  admin :2019
}

example.test {
  respond "Hello!"
}

another-example.test {
  respond "World!"
}

Using yq you can easily list via CLI:

$ curl -s "http://localhost:2019/config/apps/http/servers" \
  | yq -p=json .srv0.routes[].match[].host[]

another-example.test
example.test

You can output that to JSON/YAML/CSV, etc as an array of items too:

# This adds `-o` for output format and collects to array by wrapping with `[ ]`:
# Also uses `to_entries | .[].value` to iterate through all servers not just `srv0`
$ yq -p=json -o=json '[ to_entries | .[].value | .routes[].match[].host[] ]'
[
  "another-example.test",
  "example.test"
]

This topic was automatically closed after 30 days. New replies are no longer allowed.