mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-23 10:45:49 +03:00
Fix -port, -host, and -root flags when Caddyfile is missing
This commit is contained in:
parent
295d21f37d
commit
e8006acf80
3 changed files with 10 additions and 7 deletions
|
@ -42,11 +42,6 @@ var (
|
||||||
// If true, initialization will not show any informative output.
|
// If true, initialization will not show any informative output.
|
||||||
Quiet bool
|
Quiet bool
|
||||||
|
|
||||||
// DefaultInput is the default configuration to use when config input is empty or missing.
|
|
||||||
DefaultInput = CaddyfileInput{
|
|
||||||
Contents: []byte(fmt.Sprintf("%s:%s\nroot %s", DefaultHost, DefaultPort, DefaultRoot)),
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP2 indicates whether HTTP2 is enabled or not
|
// HTTP2 indicates whether HTTP2 is enabled or not
|
||||||
HTTP2 bool // TODO: temporary flag until http2 is standard
|
HTTP2 bool // TODO: temporary flag until http2 is standard
|
||||||
)
|
)
|
||||||
|
@ -297,7 +292,7 @@ func LoadCaddyfile(loader func() (Input, error)) (cdyfile Input, err error) {
|
||||||
|
|
||||||
// Otherwise revert to default
|
// Otherwise revert to default
|
||||||
if cdyfile == nil {
|
if cdyfile == nil {
|
||||||
cdyfile = DefaultInput
|
cdyfile = DefaultInput()
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -335,6 +335,14 @@ func NewDefault() server.Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultInput returns the default Caddyfile input
|
||||||
|
// to use when it is otherwise empty or missing.
|
||||||
|
func DefaultInput() CaddyfileInput {
|
||||||
|
return CaddyfileInput{
|
||||||
|
Contents: []byte(fmt.Sprintf("%s:%s\nroot %s", Host, Port, Root)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// These defaults are configurable through the command line
|
// These defaults are configurable through the command line
|
||||||
var (
|
var (
|
||||||
// Site root
|
// Site root
|
||||||
|
|
2
main.go
2
main.go
|
@ -113,7 +113,7 @@ func loadCaddyfile() (caddy.Input, error) {
|
||||||
contents, err := ioutil.ReadFile(caddy.DefaultConfigFile)
|
contents, err := ioutil.ReadFile(caddy.DefaultConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return caddy.DefaultInput, nil
|
return caddy.DefaultInput(), nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue