Example to append a route with the api?

1. Output of caddy version:

2. How I run Caddy:

a. System environment:

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane. -->

d. My complete Caddy config:

Paste your config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
LEAVE DOMAIN NAMES INTACT.
Make sure the backticks stay on their own lines.

3. The problem I’m having:

4. Error messages and/or full log output:

Paste logs/commands/output here.
USE THE PREVIEW PANE TO MAKE SURE IT LOOKS NICELY FORMATTED.

5. What I already tried:

cat > file.json <<!
{
“handle”: [
{
“handler”: “subroute”,
“routes”: [
{
“handle”: [
{
“handler”: “vars”,
“root”: “/home/picasso/web/example.com/public_html”
},
{
“handler”: “file_server”,
“hide”: [
“/etc/caddy/sites-enabled/example.com.conf”
]
}
]
}
]
}
],
“match”: [
{
“host”: [
example.com
]
}
],
“terminal”: true
}
!

adding a route as follows works…

curl -X POST localhost:2019/config/apps/http/servers/srv0/routes/handle[1]
-H “Content-Type: application/json”
-d “@file.json

but i want to add an arbitrary number of routes

how do i derive the offset into the ‘handle’ array to do so?

is there a better way than this?

again, i want to “append” a route - not overwrite a route!

thanks!

6. Links to relevant resources:

Please completely fill out the help topic template, as per the forum rules.

You left many sections empty, and your config has completely broken syntax, so it’s nearly impossible to read. Use code blocks for formatting.

1 Like