fix: switch to Caddy JSON config so dynamic routes work correctly

The Caddyfile created a server with an auto-generated name, not 'hiy',
so build.sh's PUT to /config/apps/http/servers/hiy/routes was creating
a parallel server that never received traffic.

- Replace Caddyfile with caddy.json that names the server 'hiy' with
  the dashboard as a catch-all fallback route
- Insert app routes at index 0 so host-matched routes are evaluated
  before the catch-all dashboard fallback
- Update docker-compose to mount caddy.json and pass --config flag
This commit is contained in:
Claude 2026-03-19 11:02:57 +00:00
parent 11db59d612
commit a8b22d8e2d
No known key found for this signature in database
3 changed files with 27 additions and 2 deletions

View file

@ -136,7 +136,7 @@ routes = [r for r in routes
if not (isinstance(r, dict)
and any(isinstance(m, dict) and new_host in m.get('host', [])
for m in r.get('match', [])))]
routes.append(json.loads(sys.argv[1]))
routes.insert(0, json.loads(sys.argv[1]))
print(json.dumps(routes))
" "$ROUTE_JSON")

View file

@ -43,9 +43,10 @@ services:
- "443:443"
- "2019:2019" # admin API
volumes:
- ../proxy/Caddyfile:/etc/caddy/Caddyfile:ro
- ../proxy/caddy.json:/etc/caddy/caddy.json:ro
- caddy-data:/data
- caddy-config:/config
command: caddy run --config /etc/caddy/caddy.json
networks:
- hiy-net
- default

24
proxy/caddy.json Normal file
View file

@ -0,0 +1,24 @@
{
"admin": {
"listen": "0.0.0.0:2019"
},
"apps": {
"http": {
"servers": {
"hiy": {
"listen": [":80", ":443"],
"routes": [
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [{"dial": "server:3000"}]
}
]
}
]
}
}
}
}
}