extract the root from the site block (get rid of double root directive)#2311
extract the root from the site block (get rid of double root directive)#2311
Conversation
|
I'm confused, why do all this, can't it just be fetched at runtime via GetVar() like file_server does in Caddy? |
We need the general root of the site block to start workers at Caddy startup. That's why we need to define it inside the php_server block. But we also need to define it for outside the php_server block so that Caddy's own file serving (such as It's also better for performance, as in that we don't always need to parse the current root anew. When the root is explicitly defined (currently), it resolves it once and then reuses it. |
|
Hmm, fair enough. I guess we could add a thing to PR welcome in Caddy if you want to wire that up. |
|
Sure, I'll look into exposing a key-value map to retrieve any other values from the site config, too. Thank you! |
|
|
|
I changed this branch to use a tagged 2.11.3.rc on my repo to let CI pass, will wait for real 2.11.3 release and then combine this with a go mod bump. |
|
What if the root has a placeholder in it though? It can't always be known at startup. |
|
Placeholder for root almost never happens, if it does it would be an env-var if anything. Not really a relevant concern. |
Then it would fail us either way. Php must know the root at provision time. |
|
I've seen some configs that use So, just be aware that if you really do piggy-back on the If you truly need the root to be 100% correct in all cases, your own |
|
That's a valid heads up. I'll try with using placeholders/env variables and test with that. That's on the consumer of the If anything this probably means we should keep the localhost
root {placeholder} # resolves to != /path
php_server {
root /path
}wouldn't explode in the users face during runtime. At least this way it could warn (/fail with workers) on startup. |
I got tired of writing
so here's my idea of fixing it. This accounts for multiple roots being defined with matchers, but it requires a
root /path/to/rootdirective to be defined, as we have no way of distinguishing multiple parsedroot <matcher> <path>directives. Or we can, but we can't figure out which one would be a wildcard root.@mholt @francislavoie would you be generally open to exporting
Helpe::parentBlock(either through aServerBlock()function, or by capitalizing it likeh.State)? Alternatively, is there a way to hook into the site block parsing? I thought we could register our own "root" directive, but passing it back into caddy's other unexported fields would be just as dirty.