Skip to content

Commit adde3a6

Browse files
fix: handle nested config result from Caddy adapt endpoint
- Added unwrapping logic to handle Caddy's /adapt endpoint response structure where config is nested under "result" key - Added type assertion and error handling for the result map conversion - Updated LoadCaddyfile to ensure proper config structure before sending to /load endpoint
1 parent 6c9581b commit adde3a6

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/hecate/caddy_admin_api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ func (c *CaddyAdminClient) LoadCaddyfile(ctx context.Context, caddyfile string)
169169
return fmt.Errorf("failed to adapt Caddyfile: %w", err)
170170
}
171171

172+
if result, ok := config["result"]; ok {
173+
resultMap, ok := result.(map[string]interface{})
174+
if !ok {
175+
return fmt.Errorf("adapted config result has unexpected type %T", result)
176+
}
177+
// Caddy /adapt wraps the real config under "result"; unwrap so /load sees the root apps/logging keys.
178+
config = resultMap
179+
}
180+
172181
// Step 2: Load the JSON config
173182
if err := c.LoadConfig(ctx, config); err != nil {
174183
return fmt.Errorf("failed to load adapted config: %w", err)

0 commit comments

Comments
 (0)