From e9b9432da5e046b7c95c5a0e6c5fc5a087b75be4 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 10 Nov 2015 15:06:47 -0700 Subject: [PATCH] "-conf stdin" required to pipe in Caddyfile Some programs (Node.js, supervisor, etc.) open a stdin pipe by default and don't use it, causing Caddy to block. It is their error, but we have to try to accommodate unfortunately. To fix this more universally, parent must explicitly set -conf to "stdin" to read from pipe. --- main.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 6fab32746..61b5c34aa 100644 --- a/main.go +++ b/main.go @@ -117,25 +117,17 @@ func mustLogFatal(args ...interface{}) { } func loadCaddyfile() (caddy.Input, error) { - // First try stdin pipe - cdyfile, err := caddy.CaddyfileFromPipe(os.Stdin) - if err != nil { - return nil, err - } - if cdyfile != nil { - // it is an error if -conf is also specified because, which to use? - if conf != "" { - return nil, errors.New("load: can't choose between stdin pipe and -conf flag") - } - return cdyfile, err - } - - // -conf flag + // Try -conf flag if conf != "" { + if conf == "stdin" { + return caddy.CaddyfileFromPipe(os.Stdin) + } + contents, err := ioutil.ReadFile(conf) if err != nil { return nil, err } + return caddy.CaddyfileInput{ Contents: contents, Filepath: conf,