Browse Source

cmd: file-server: add --access-log flag (#3454)

master
Rui Lopes 5 years ago
committed by GitHub
parent
commit
aa20878887
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      modules/caddyhttp/fileserver/command.go

7
modules/caddyhttp/fileserver/command.go

@ -33,7 +33,7 @@ func init() {
caddycmd.RegisterCommand(caddycmd.Command{ caddycmd.RegisterCommand(caddycmd.Command{
Name: "file-server", Name: "file-server",
Func: cmdFileServer, 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", Short: "Spins up a production-ready file server",
Long: ` Long: `
A simple but production-ready file server. Useful for quick deployments, A simple but production-ready file server. Useful for quick deployments,
@ -55,6 +55,7 @@ respond with a file listing.`,
fs.String("listen", "", "The address to which to bind the listener") fs.String("listen", "", "The address to which to bind the listener")
fs.Bool("browse", false, "Enable directory browsing") fs.Bool("browse", false, "Enable directory browsing")
fs.Bool("templates", false, "Enable template rendering") fs.Bool("templates", false, "Enable template rendering")
fs.Bool("access-log", false, "Enable the access log")
return fs return fs
}(), }(),
}) })
@ -68,6 +69,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
listen := fs.String("listen") listen := fs.String("listen")
browse := fs.Bool("browse") browse := fs.Bool("browse")
templates := fs.Bool("templates") templates := fs.Bool("templates")
accessLog := fs.Bool("access-log")
var handlers []json.RawMessage var handlers []json.RawMessage
@ -107,6 +109,9 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
} }
} }
server.Listen = []string{listen} server.Listen = []string{listen}
if accessLog {
server.Logs = &caddyhttp.ServerLogConfig{}
}
httpApp := caddyhttp.App{ httpApp := caddyhttp.App{
Servers: map[string]*caddyhttp.Server{"static": server}, Servers: map[string]*caddyhttp.Server{"static": server},

Loading…
Cancel
Save