Skip to content

Commit

Permalink
cmd: file-server: add --access-log flag (#3454)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed May 26, 2020
1 parent c1e5c09 commit aa20878
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/caddyhttp/fileserver/command.go
Expand Up @@ -33,7 +33,7 @@ func init() {
caddycmd.RegisterCommand(caddycmd.Command{
Name: "file-server",
Func: cmdFileServer,
Usage: "[--domain <example.com>] [--root <path>] [--listen <addr>] [--browse]",
Usage: "[--domain <example.com>] [--root <path>] [--listen <addr>] [--browse] [--access-log]",
Short: "Spins up a production-ready file server",
Long: `
A simple but production-ready file server. Useful for quick deployments,
Expand All @@ -55,6 +55,7 @@ respond with a file listing.`,
fs.String("listen", "", "The address to which to bind the listener")
fs.Bool("browse", false, "Enable directory browsing")
fs.Bool("templates", false, "Enable template rendering")
fs.Bool("access-log", false, "Enable the access log")
return fs
}(),
})
Expand All @@ -68,6 +69,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
listen := fs.String("listen")
browse := fs.Bool("browse")
templates := fs.Bool("templates")
accessLog := fs.Bool("access-log")

var handlers []json.RawMessage

Expand Down Expand Up @@ -107,6 +109,9 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
}
}
server.Listen = []string{listen}
if accessLog {
server.Logs = &caddyhttp.ServerLogConfig{}
}

httpApp := caddyhttp.App{
Servers: map[string]*caddyhttp.Server{"static": server},
Expand Down

0 comments on commit aa20878

Please sign in to comment.