Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
fileserver: Add --templates flag to file-server command
Matthew Holt committed
Mar 14, 2020 at 23:31 UTC
2ce3deb540fe14ef0ef8cb733d592d2839a88624
1 file changed
+15
-6
modules/caddyhttp/fileserver/command.go
+15
-6
@@ -25,6 +25,7 @@ import (
25
"github.com/caddyserver/caddy/v2/caddyconfig"
26
caddycmd "github.com/caddyserver/caddy/v2/cmd"
27
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
28
+ caddytpl "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
29
"github.com/caddyserver/certmagic"
30
)
31
@@ -52,7 +53,8 @@ respond with a file listing.`,
53
fs.String("domain", "", "Domain name at which to serve the files")
54
fs.String("root", "", "The path to the root of the site")
55
fs.String("listen", "", "The address to which to bind the listener")
55
- fs.Bool("browse", false, "Whether to enable directory browsing")
56
+ fs.Bool("browse", false, "Enable directory browsing")
57
+ fs.Bool("templates", false, "Enable template rendering")
58
return fs
59
}(),
60
})
@@ -63,17 +65,24 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
65
root := fs.String("root")
66
listen := fs.String("listen")
67
browse := fs.Bool("browse")
68
+ templates := fs.Bool("templates")
69
+
70
+ var handlers []json.RawMessage
71
+
72
+ if templates {
73
+ handler := caddytpl.Templates{FileRoot: root}
74
+ handlers = append(handlers, caddyconfig.JSONModuleObject(handler, "handler", "templates", nil))
75
+ }
76
77
handler := FileServer{Root: root}
78
if browse {
79
handler.Browse = new(Browse)
80
}
81
72
- route := caddyhttp.Route{
73
- HandlersRaw: []json.RawMessage{
74
- caddyconfig.JSONModuleObject(handler, "handler", "file_server", nil),
75
- },
76
- }
82
+ handlers = append(handlers, caddyconfig.JSONModuleObject(handler, "handler", "file_server", nil))
83
+
84
+ route := caddyhttp.Route{HandlersRaw: handlers}
85
+
86
if domain != "" {
87
route.MatcherSetsRaw = []caddy.ModuleMap{
88
caddy.ModuleMap{