@marcel91200 / caddy Mirror · read-only / commits / ed8bb13c
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 23:15 UTC

fileserver: Export BrowseTemplate

This allows programs embedding Caddy to customize the browse template.

Matthew Holt committed Aug 29, 2023 at 09:34 UTC ed8bb13c5df7656647ca7fc1fd09237631a6767c
2 files changed +10 -4
modules/caddyhttp/fileserver/browse.go
+9 -3
@@ -36,12 +36,18 @@ import (
36 "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
37 )
38
39 +// BrowseTemplate is the default template document to use for
40 +// file listings. By default, its default value is an embedded
41 +// document. You can override this value at program start, or
42 +// if you are running Caddy via config, you can specify a
43 +// custom template_file in the browse configuration.
44 +//
45 //go:embed browse.html
40 -var defaultBrowseTemplate string
46 +var BrowseTemplate string
47
48 // Browse configures directory browsing.
49 type Browse struct {
44 - // Use this template file instead of the default browse template.
50 + // Filename of the template to use instead of the embedded browse template.
51 TemplateFile string `json:"template_file,omitempty"`
52 }
53
@@ -205,7 +211,7 @@ func (fsrv *FileServer) makeBrowseTemplate(tplCtx *templateContext) (*template.T
211 }
212 } else {
213 tpl = tplCtx.NewTemplate("default_listing")
208 - tpl, err = tpl.Parse(defaultBrowseTemplate)
214 + tpl, err = tpl.Parse(BrowseTemplate)
215 if err != nil {
216 return nil, fmt.Errorf("parsing default browse template: %v", err)
217 }
modules/caddyhttp/fileserver/command.go
+1 -1
@@ -66,7 +66,7 @@ respond with a file listing.`,
66 Short: "Exports the default file browser template",
67 Example: "caddy file-server export-template > browse.html",
68 RunE: func(cmd *cobra.Command, args []string) error {
69 - _, err := io.WriteString(os.Stdout, defaultBrowseTemplate)
69 + _, err := io.WriteString(os.Stdout, BrowseTemplate)
70 return err
71 },
72 })