mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-28 04:45:56 +03:00
cmd: file-server: add --access-log flag (#3454)
This commit is contained in:
parent
c1e5c09294
commit
aa20878887
1 changed files with 6 additions and 1 deletions
|
@ -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…
Reference in a new issue