caddy -version)?8de1a762273323608d9d9080c42057d1814070b6
I'll try to use IDs in JSON to identify the objects in a servers 'routes' section.
Base configuration JSON:
{
"admin": {
"disabled": false,
"listen": ":2019",
"enforce_origin": false,
"origins": []
},
"apps": {
"http": {
"http_port": 8080,
"https_port": 8443,
"servers": {
"proxy": {
"listen": [
":8080",
":8443"
],
"routes": [
]
}
}
},
"tls": {
"automation": {},
"session_tickets": {}
}
}
}
Add first route using the API:
$ curl -X POST -H 'Content-Type: application/json; charset=utf-8' http://localhost:2019/config/apps/http/servers/proxy/routes/ -d @- << EOF
{
"@id": "foo",
"match": [
{
"host": [
"foo.localhost"
]
}
],
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "test.example.com:80"
}
]
}
]
}
EOF
Add second route using the API:
$ curl -X POST -H 'Content-Type: application/json; charset=utf-8' http://localhost:2019/config/apps/http/servers/proxy/routes/ -d @- << EOF
{
"@id": "bar",
"match": [
{
"host": [
"bar.localhost"
]
}
],
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "test.example.com:80"
}
]
}
]
}
EOF
Removing first route using the API:
curl -X DELETE http://localhost:2019/id/foo/
But it results in:
{"error":"unknown object ID 'foo'"}
_All configurations are already shown in 2._
$ caddy run --config /etc/caddy/config.json
_none_
The expectation is, that I can remove the route element form the list by using it's ID.
{"error":"unknown object ID 'foo'"}
It seems that only the last ID will be stored.
It seems that only the last ID will be stored.
Currently, I'll fetch the whole routes list, search the entry I want to remove.
curl http://localhost:2019/config/apps/http/servers/proxy/routes/
Then I call delete using the index of the element.
curl -X DELETE http://localhost:2019/config/apps/http/servers/proxy/routes/1
_none_
Ah, thanks for the report. Working on a fix...
@FrankGiesecke Thanks to your detailed report and very easy reproduce instructions, I was able to find and fix the bug pretty easily. We were wiping out previous ID's, oops.
Now we preserve them, so you'll see them in your GET requests for current config. We just strip them out of the JSON internally using a regex. :joy: It works though. There is one other way we could do it... by deleting the "@id" fields as we find and index them (like we were before), then JSON-encode, then re-add the "@id" fields into our stored internal representation (rawCfg). We just have to make sure the resulting JSON doesn't have them, but our internal representation does. I just opted for the regex cause it's a quicker fix and seems to work pretty well.
Can you build from source (v2 branch) and try again and let me know how it goes for you?
@mholt It works great 馃憤
Thanks for the fast fix.
It's because your issue was so well-written. I will probably refer to it as a model for others.
Most helpful comment
@mholt It works great 馃憤
Thanks for the fast fix.