summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/fileserver/command.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-03-14 23:31:52 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-03-14 23:31:52 -0600
commit2ce3deb540fe14ef0ef8cb733d592d2839a88624 (patch)
tree9e5105a6383b75f712cc6d51a86b39cec234839d /modules/caddyhttp/fileserver/command.go
parentacf4dde1dd1fa2d30b76c19009e5a7019cce0b2b (diff)
fileserver: Add --templates flag to file-server command
Diffstat (limited to 'modules/caddyhttp/fileserver/command.go')
-rw-r--r--modules/caddyhttp/fileserver/command.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/modules/caddyhttp/fileserver/command.go b/modules/caddyhttp/fileserver/command.go
index 943ddaa..bd740e8 100644
--- a/modules/caddyhttp/fileserver/command.go
+++ b/modules/caddyhttp/fileserver/command.go
@@ -25,6 +25,7 @@ import (
"github.com/caddyserver/caddy/v2/caddyconfig"
caddycmd "github.com/caddyserver/caddy/v2/cmd"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
+ caddytpl "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
"github.com/caddyserver/certmagic"
)
@@ -52,7 +53,8 @@ respond with a file listing.`,
fs.String("domain", "", "Domain name at which to serve the files")
fs.String("root", "", "The path to the root of the site")
fs.String("listen", "", "The address to which to bind the listener")
- fs.Bool("browse", false, "Whether to enable directory browsing")
+ fs.Bool("browse", false, "Enable directory browsing")
+ fs.Bool("templates", false, "Enable template rendering")
return fs
}(),
})
@@ -63,17 +65,24 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
root := fs.String("root")
listen := fs.String("listen")
browse := fs.Bool("browse")
+ templates := fs.Bool("templates")
+
+ var handlers []json.RawMessage
+
+ if templates {
+ handler := caddytpl.Templates{FileRoot: root}
+ handlers = append(handlers, caddyconfig.JSONModuleObject(handler, "handler", "templates", nil))
+ }
handler := FileServer{Root: root}
if browse {
handler.Browse = new(Browse)
}
- route := caddyhttp.Route{
- HandlersRaw: []json.RawMessage{
- caddyconfig.JSONModuleObject(handler, "handler", "file_server", nil),
- },
- }
+ handlers = append(handlers, caddyconfig.JSONModuleObject(handler, "handler", "file_server", nil))
+
+ route := caddyhttp.Route{HandlersRaw: handlers}
+
if domain != "" {
route.MatcherSetsRaw = []caddy.ModuleMap{
caddy.ModuleMap{