caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Home Page:https://caddyserver.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API: fail to update config with text/caddyfile

tetra12 opened this issue · comments

I'm trying to programmatically update caddy with a simple http call with a caddyfile as per docs.
Getting 400 for the text/caddyfile data type:

res, err := s.httpClient.Post(s.cfg.AdminURL, "text/caddyfile", byteBuffer)
if err != nil {
  return err
}
ERROR   admin.api       request error   {"error": "unacceptable content-type: text/caddyfile; 'application/json' required", "status_code": 400}

Config works fine for the application/json type.

Caddy: v2.7.6 (master)
Go: 1.22.0
OS: Ubuntu 22.04

What's s.cfg.AdminURL set to? You should use the /load endpoint: https://caddyserver.com/docs/api#post-load

@francislavoie Yes, used an invalid URL. Thanks for spotting out 👍