Snippet / Import woes


(p3lim) #1

So I’m trying to wrap my head around snippets and imports, and trying to apply it to the following:

$ tree /config
├── Caddyfile
└── domains
    ├── domain1.com
    └── domain2.com

$ cat /config/Caddyfile
import domains/*

If I modify Caddyfile to the following:

(test) {
	root /www
}
import domains/*

And try to use it in domains/domain1.com like so:

foo.domain1.com {
	import test
}

I get the following error:
“Error during parsing: File to import not found: /config/domains/test”

If I create the snippet in domains/domain1.com (where I use it), I get the same error :confused:

So what I gathered from this is that I can’t use snippets in imported files, this seems unintentional / bugged.


(Matthew Fay) #2

Hi @p3lim,

No, snippets are only usable in the main Caddyfile itself, it doesn’t cross the “import boundary”.

I believe it’s always been this way, but the docs don’t mention this limitation. If you’d like, open an issue at https://github.com/mholt/caddy/issues/new - either as a feature request, or to get the docs updated.


(p3lim) #3