1. Transitioning to API usage, difficulty with paths and JSON maintenance
TLDR:
- How can the complexity of my CaddyFile be reduced to result in a less complex JSON?
- Why can’t @ID’s be added to CaddyFile to be inserted into JSON upon adaptation?
- Why is it so difficult to determine the path in a JSON for API usage?
- How is a long JSON maintained? It’s not obviously easy to make manual edits like adding path handlers and reverse proxies. Can work like this be done with the API?
Adapted from what I thought was a simple 52 line CaddyFile, the resulting JSON is almost 700 lines.
I want to use the PATCH command to add basic auth entries under multiple apps in the config, and to me, reading the JSON and figuring out the path is not so simple.
I had success manually entering a @id into a part of the config, and using the patch command. I also tried ChatGPT to find the right path, but that was unsuccessful.
Basically, I see two options.
Every time I want to update the config or add an app, I edit the CaddyFile, adapt it to JSON, and then manually insert all the @ID tags.
OR
Maintain the JSON itself, which is very long to edit by hand.
Am I missing something? I feel like this should be simpler than Im making it.
I wish I could insert @ID’s into the CaddyFile and make pathing easier, but after some searching this does not seem possible.
3. Caddy version:
v2.8.4
4. How I installed and ran Caddy:
I installed caddy on linux and have run from CaddyFile and adapted JSON
a. System environment:
Ubuntu 24 on raspberry pi
d. My complete Caddy config:
Here is my Caddyfile:
(basic-auth) {
route {
header User-ID {http.auth.user.id}
}
basic_auth {
email@email.com hash
}
}
website.com {
root * /home/lesko/public-website
file_server
header Access-Control-Expose-Headers "User-ID"
handle_path /employees/pto/request* {
import basic-auth
reverse_proxy 0.0.0.0:8502
}
handle_path /employees/pto/total* {
import basic-auth
reverse_proxy 0.0.0.0:8503
}
handle_path /employees/pto/approve* {
import basic-auth
reverse_proxy 0.0.0.0:8504
}
handle_path /employees/pto/calendar* {
import basic-auth
reverse_proxy 0.0.0.0:8505
}
handle_path /employees/pto/manage* {
import basic-auth
reverse_proxy 0.0.0.0:8506
}
handle_path /employees/supplies* {
reverse_proxy 0.0.0.0:8507
}
handle_path /employees/query_sql* {
import basic-auth
reverse_proxy 0.0.0.0:8508
}
handle_path /employees/database* {
import basic-auth
reverse_proxy 0.0.0.0:8509
}
handle_path /employees* {
import basic-auth
reverse_proxy 0.0.0.0:8001
}
}