mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-27 09:12:31 -04:00
Implement per-site index (#1906)
This commit is contained in:
committed by
Toby Allen
parent
fc75527eb5
commit
f7a70266ed
@@ -19,7 +19,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||||
"github.com/mholt/caddy/caddyhttp/staticfiles"
|
||||
)
|
||||
|
||||
func (h Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
@@ -44,7 +43,7 @@ outer:
|
||||
matches := httpserver.Path(urlPath).Matches(rule.Path)
|
||||
// Also check IndexPages when requesting a directory
|
||||
if !matches {
|
||||
indexFile, isIndexFile := httpserver.IndexFile(h.Root, urlPath, staticfiles.IndexPages)
|
||||
indexFile, isIndexFile := httpserver.IndexFile(h.Root, urlPath, h.indexPages)
|
||||
if isIndexFile {
|
||||
matches = httpserver.Path(indexFile).Matches(rule.Path)
|
||||
}
|
||||
|
||||
@@ -393,7 +393,8 @@ func TestMiddlewareShouldPushIndexFile(t *testing.T) {
|
||||
{Path: "/index.css", Method: http.MethodGet},
|
||||
}},
|
||||
},
|
||||
Root: http.Dir(root),
|
||||
Root: http.Dir(root),
|
||||
indexPages: []string{indexFile},
|
||||
}
|
||||
|
||||
indexFilePath := filepath.Join(root, indexFile)
|
||||
|
||||
@@ -36,9 +36,10 @@ type (
|
||||
|
||||
// Middleware supports pushing resources to clients
|
||||
Middleware struct {
|
||||
Next httpserver.Handler
|
||||
Rules []Rule
|
||||
Root http.FileSystem
|
||||
Next httpserver.Handler
|
||||
Rules []Rule
|
||||
Root http.FileSystem
|
||||
indexPages []string // will be injected from SiteConfig on setup
|
||||
}
|
||||
|
||||
ruleOp func([]Resource)
|
||||
|
||||
@@ -50,7 +50,7 @@ func setup(c *caddy.Controller) error {
|
||||
|
||||
cfg := httpserver.GetConfig(c)
|
||||
cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
||||
return Middleware{Next: next, Rules: rules, Root: http.Dir(cfg.Root)}
|
||||
return Middleware{Next: next, Rules: rules, Root: http.Dir(cfg.Root), indexPages: cfg.IndexPages}
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user