Commit 1e730a74 authored by Matt Holt's avatar Matt Holt

Merge pull request #50 from ChannelMeter/core/bind_address

core: Add the option to specify what address to bind on in Caddyfile
parents 4637f14b 46f79307
...@@ -43,6 +43,7 @@ var directiveOrder = []directive{ ...@@ -43,6 +43,7 @@ var directiveOrder = []directive{
// Essential directives that initialize vital configuration settings // Essential directives that initialize vital configuration settings
{"root", setup.Root}, {"root", setup.Root},
{"tls", setup.TLS}, {"tls", setup.TLS},
{"bind", setup.BindHost},
// Other directives that don't create HTTP handlers // Other directives that don't create HTTP handlers
{"startup", setup.Startup}, {"startup", setup.Startup},
......
package setup
import "github.com/mholt/caddy/middleware"
func BindHost(c *Controller) (middleware.Middleware, error) {
for c.Next() {
if !c.Args(&c.BindHost) {
return nil, c.ArgErr()
}
}
return nil, nil
}
...@@ -11,6 +11,9 @@ type Config struct { ...@@ -11,6 +11,9 @@ type Config struct {
// The hostname or IP on which to serve // The hostname or IP on which to serve
Host string Host string
// The host address to bind on - defaults to (virtual) Host if empty
BindHost string
// The port to listen on // The port to listen on
Port string Port string
...@@ -44,6 +47,9 @@ type Config struct { ...@@ -44,6 +47,9 @@ type Config struct {
// Address returns the host:port of c as a string. // Address returns the host:port of c as a string.
func (c Config) Address() string { func (c Config) Address() string {
if c.BindHost != "" {
return net.JoinHostPort(c.BindHost, c.Port)
}
return net.JoinHostPort(c.Host, c.Port) return net.JoinHostPort(c.Host, c.Port)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment