caddy icon indicating copy to clipboard operation
caddy copied to clipboard

The name `example.Caddyfile` is not considered a valid Caddyfile

Open coolaj86 opened this issue 2 years ago • 6 comments

caddy run --config ./example.Caddyfile
2023/10/22 06:21:11.620	INFO	using provided configuration	{"config_file": "./example.Caddyfile", "config_adapter": ""}
Error: loading initial config: decoding request body: invalid character '#' looking for beginning of value

But if I simply rename the:

caddy run --config ./Caddyfile.example

Then it works as expected.

It seems like .Caddyfile (or really anything that isn't .json) should be considered a Caddyfile unless some sort of matching logic for some particular adapter says otherwise.

coolaj86 avatar Oct 22 '23 06:10 coolaj86

Any file that starts with Caddyfile will automatically be assumed to be a Caddyfile. From our docs:

If it is called something else that doesn't start with "Caddyfile", you will need to specify --adapter caddyfile.

So you can always specify the adapter name if the file name doesn't conform.

That said, I wonder if we should treat any file name that has Caddyfile in it as a Caddyfile... but maybe that's too liberal.

mholt avatar Oct 22 '23 06:10 mholt

  • equals Caddyfile
  • Has prefix Caddyfile.
  • Has suffix .Caddyfile

OSes and editors expect to know a file by its specific name, suffix, or magic bytes.

the only other file type I know of that started out with using a prefix as its type identifier is .env.xyz, and its definitely more difficult to get editors to recognize it correctly.

Being consistent with decades long tried and true conventions is generally good for machines and users alike.

coolaj86 avatar Oct 22 '23 16:10 coolaj86

Docker does this with the Dockerfile though too. And Vagrant has the Vagrantfile. It's not something we invented nor is it uncommon. Docker is practically everywhere.

But yeah, maybe containing the word Caddyfile is good enough, since it would have to be explicitly given as the config file anyway, so I don't foresee many false positives here. We only automatically use files named exactly Caddyfile.

mholt avatar Oct 22 '23 17:10 mholt

I think .Caddyfile suffix is okay to support. Maybe even .caddyfile.

francislavoie avatar Oct 22 '23 20:10 francislavoie

Case insensitive options would also be good for those that are allergic to the shift key.

cwbriscoe avatar Oct 26 '23 03:10 cwbriscoe

Hi @mholt and @francislavoie, I've submitted a pull request to handle this case. Let me know if there are any other conditions you would like to handle for the Caddyfile naming convention.

omalk98 avatar Oct 28 '23 20:10 omalk98