Hi,
first, thank you to the Caddy developers for their work, I discovered it recently, and looks great!
I think it would be useful to be able to do some queries using the JSON API, questions like, what is the name of the server listening on port 8080? Or, what route matches a request to test.com/api?
Do you think it would be useful? Are there some plans for that?
My use case is that I want to add a new route with the API, but I don’t know if there is already a server listening on the port I want to use. Depending on if there is one or not, I want to create a new server or a route on an existing server.
Right now I see 2 options, one is to do a request to get the whole configuration and parse it myself. The other one is to try to create a new server on the port I’m interested in and if there is an error I could extract the server name from the error, e.g.:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"listen" :[":8081"]}' \
"http://localhost:2020/config/apps/http/servers/myserver"
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Date: Tue, 08 Sep 2020 21:40:04 GMT
Content-Length: 182
Connection: close
{"error":"loading new config: loading http app module: http: invalid configuration: server myserver: listener address repeated: tcp/:8081 (already claimed by server 'myserver')"}
But both solutions seem a bit hacky to me, I’d prefer a more direct way to do those queries.