caddy icon indicating copy to clipboard operation
caddy copied to clipboard

Snippets can't be imported in named routes

Open loichyan opened this issue 1 year ago • 2 comments
trafficstars

Description

import is not recognized in named routes. With the following configuration:

# Caddyfile
(mysnippet) {
	encode zstd gzip
}

&(myroute) {
	import mysnippet
	respond "Hello, Caddy!"
}

example.com {
	invoke myroute
}

It results in:

$ caddy adapt -c Caddyfile
Error: unrecognized directive: import - are you sure your Caddyfile structure (nesting and braces) is correct?, at config/caddy/Caddyfile:8

Environment

  • Caddy version: 2.8.4
  • Platform: Linux (Fedora Silverblue 40)

I also reproduced it on the latest commit (https://github.com/caddyserver/caddy/commit/f8861ca16bd475e8519e7dbf5a2b55e81b329874).

loichyan avatar Jul 03 '24 03:07 loichyan

Hi, I just ran into this limitation myself (Caddy v2.10.0). Is this considered a bug or is this by design? I might be able to send an update to the documentation in this case. To me, it sounds like this contradicts the following statement from the import docs:

it is evaluated before the structure is parsed, and it can appear anywhere in the Caddyfile.

fnetX avatar Apr 24 '25 17:04 fnetX

I haven't had a chance to dig into this. Named routes were added as a relatively new feature, they work similarly to import at the Caddyfile parsing level so there's probably a bit of contention that makes them not play nice with eachother. PRs welcome in case someone wants to take a shot at fixing it.

francislavoie avatar Apr 24 '25 17:04 francislavoie