-
Notifications
You must be signed in to change notification settings - Fork 444
extract the root from the site block (get rid of double root directive) #2311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
3a54a40
bcf3e68
8d14123
824f93f
0d0f336
c8c459d
d400fe5
1d9fc41
98268f6
df197b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ type FrankenPHPModule struct { | |
| mercureContext | ||
| hotReloadContext | ||
|
|
||
| // Root sets the root folder to the site. Default: `root` directive, or the path of the public directory of the embed app it exists. | ||
| // Deprecated: Use the `root` directive in the site block instead. | ||
| Root string `json:"root,omitempty"` | ||
| // SplitPath sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the CGI script to use. Default: `.php`. | ||
|
||
| SplitPath []string `json:"split_path,omitempty"` | ||
|
|
@@ -261,6 +261,7 @@ func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { | |
| for d.NextBlock(0) { | ||
| switch d.Val() { | ||
| case "root": | ||
| caddy.Log().Named("caddyfile").Warn("DEPRECATED: the 'root' subdirective of 'php'/'php_server' is deprecated, use the 'root' directive in the site block instead") | ||
| if !d.NextArg() { | ||
| return d.ArgErr() | ||
| } | ||
|
|
@@ -418,6 +419,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) | |
| // parse the php_server subdirectives | ||
| switch dispenser.Val() { | ||
| case "root": | ||
| caddy.Log().Named("caddyfile").Warn("DEPRECATED: the 'root' subdirective of 'php_server' is deprecated, use the 'root' directive in the site block instead") | ||
| if !dispenser.NextArg() { | ||
| return nil, dispenser.ArgErr() | ||
| } | ||
|
|
@@ -470,6 +472,16 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) | |
| return nil, err | ||
| } | ||
|
|
||
| // If no root was specified inside php_server, inherit it from the site-level root directive. | ||
| // Skip roots containing placeholders (e.g. {env.APP_ROOT}). | ||
| // We can check for `{` here because {$ENV} vars are already resolved earlier | ||
| if phpsrv.Root == "" { | ||
| if siteRoot := extractSiteRoot(h); siteRoot != "" && !strings.Contains(siteRoot, "{") { | ||
| phpsrv.Root = siteRoot | ||
| fsrv.Root = siteRoot | ||
| } | ||
| } | ||
|
|
||
| if frankenphp.EmbeddedAppPath != "" { | ||
| if phpsrv.Root == "" { | ||
| phpsrv.Root = filepath.Join(frankenphp.EmbeddedAppPath, defaultDocumentRoot) | ||
|
|
@@ -675,6 +687,14 @@ func prependWorkerRoutes(routes caddyhttp.RouteList, h httpcaddyfile.Helper, f F | |
| return routes | ||
| } | ||
|
|
||
| func extractSiteRoot(h httpcaddyfile.Helper) string { | ||
| // Caddy stores only unmatched or wildcard matcher roots | ||
| if root, ok := h.BlockState["root"].(string); ok { | ||
| return root | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // Interface guards | ||
| var ( | ||
| _ caddy.Provisioner = (*FrankenPHPModule)(nil) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this test also green on
main? Maybe would make sense to test with multiplephp_serversand multiple roots.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would fail to start because it wouldn't find the
worker-with-counter.php. But yes, I'll do that!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh because the path will be relative to the working directory and not relative to the server root. I guess it makes sense then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes this a small BC break though for people expecting the working directory. I wonder if we should check both relative path to root and relative path to working directory. Or at least warn if one or the other was found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly I think we can't do this at all, after all.
#2311 (comment)
Ugh, I'm so tired of double typing the root :(