aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/fileserver
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2023-08-29 09:34:20 -0600
committerMatthew Holt <[email protected]>2023-08-29 09:34:20 -0600
commited8bb13c5df7656647ca7fc1fd09237631a6767c (patch)
tree4119bcd50c6ee18a8fb2d4f268bca7267d8ac5ff /modules/caddyhttp/fileserver
parentb7e472d54884de4ecd6147784c74fb448180e9d1 (diff)
downloadcaddy-ed8bb13c5df7656647ca7fc1fd09237631a6767c.tar.gz
caddy-ed8bb13c5df7656647ca7fc1fd09237631a6767c.zip
fileserver: Export BrowseTemplate
This allows programs embedding Caddy to customize the browse template.
Diffstat (limited to 'modules/caddyhttp/fileserver')
-rw-r--r--modules/caddyhttp/fileserver/browse.go12
-rw-r--r--modules/caddyhttp/fileserver/command.go2
2 files changed, 10 insertions, 4 deletions
diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go
index 917d14fde..81eb08592 100644
--- a/modules/caddyhttp/fileserver/browse.go
+++ b/modules/caddyhttp/fileserver/browse.go
@@ -36,12 +36,18 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
)
+// BrowseTemplate is the default template document to use for
+// file listings. By default, its default value is an embedded
+// document. You can override this value at program start, or
+// if you are running Caddy via config, you can specify a
+// custom template_file in the browse configuration.
+//
//go:embed browse.html
-var defaultBrowseTemplate string
+var BrowseTemplate string
// Browse configures directory browsing.
type Browse struct {
- // Use this template file instead of the default browse template.
+ // Filename of the template to use instead of the embedded browse template.
TemplateFile string `json:"template_file,omitempty"`
}
@@ -205,7 +211,7 @@ func (fsrv *FileServer) makeBrowseTemplate(tplCtx *templateContext) (*template.T
}
} else {
tpl = tplCtx.NewTemplate("default_listing")
- tpl, err = tpl.Parse(defaultBrowseTemplate)
+ tpl, err = tpl.Parse(BrowseTemplate)
if err != nil {
return nil, fmt.Errorf("parsing default browse template: %v", err)
}
diff --git a/modules/caddyhttp/fileserver/command.go b/modules/caddyhttp/fileserver/command.go
index fb145cb06..895c4f06d 100644
--- a/modules/caddyhttp/fileserver/command.go
+++ b/modules/caddyhttp/fileserver/command.go
@@ -66,7 +66,7 @@ respond with a file listing.`,
Short: "Exports the default file browser template",
Example: "caddy file-server export-template > browse.html",
RunE: func(cmd *cobra.Command, args []string) error {
- _, err := io.WriteString(os.Stdout, defaultBrowseTemplate)
+ _, err := io.WriteString(os.Stdout, BrowseTemplate)
return err
},
})