mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Set the default hostname to "0.0.0.0" from "127.0.0.1" - as golang's net.Listener does by default
I changed that because some guys has problems in their hosting machines, and they should use the "127.0..0.1" instead of "0.0.0.0", if you have problems just pass `iris.Listen("127.0.0.1:8080") instead of `iris.Listen(":8080")`
This commit is contained in:
parent
352b297977
commit
0dbab32d9d
|
@ -11,8 +11,8 @@ import (
|
||||||
|
|
||||||
// Default values for base Server conf
|
// Default values for base Server conf
|
||||||
const (
|
const (
|
||||||
// DefaultServerHostname returns the default hostname which is 127.0.0.1
|
// DefaultServerHostname returns the default hostname which is 0.0.0.0
|
||||||
DefaultServerHostname = "127.0.0.1"
|
DefaultServerHostname = "0.0.0.0"
|
||||||
// DefaultServerPort returns the default port which is 8080
|
// DefaultServerPort returns the default port which is 8080
|
||||||
DefaultServerPort = 8080
|
DefaultServerPort = 8080
|
||||||
// DefaultMaxRequestBodySize is 8MB
|
// DefaultMaxRequestBodySize is 8MB
|
||||||
|
@ -37,7 +37,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultServerAddr the default server addr which is: 127.0.0.1:8080
|
// DefaultServerAddr the default server addr which is: 0.0.0.0:8080
|
||||||
DefaultServerAddr = DefaultServerHostname + ":" + strconv.Itoa(DefaultServerPort)
|
DefaultServerAddr = DefaultServerHostname + ":" + strconv.Itoa(DefaultServerPort)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -238,9 +238,14 @@ func (ctx *Context) VirtualHostname() string {
|
||||||
}
|
}
|
||||||
if idxDotAnd := strings.LastIndexByte(hostname, '.'); idxDotAnd > 0 {
|
if idxDotAnd := strings.LastIndexByte(hostname, '.'); idxDotAnd > 0 {
|
||||||
s := hostname[idxDotAnd:]
|
s := hostname[idxDotAnd:]
|
||||||
|
// means that we have the request's host mymachine.com or 127.0.0.1/0.0.0.0, but for the second option we will need to replace it with the hostname that the dev was registered
|
||||||
|
// this needed to parse correct the {{ url }} iris global template engine's function
|
||||||
if s == ".1" {
|
if s == ".1" {
|
||||||
hostname = strings.Replace(hostname, "127.0.0.1", virtualhost, 1)
|
hostname = strings.Replace(hostname, "127.0.0.1", virtualhost, 1)
|
||||||
|
} else if s == ".0" {
|
||||||
|
hostname = strings.Replace(hostname, "0.0.0.0", virtualhost, 1)
|
||||||
}
|
}
|
||||||
|
//
|
||||||
} else {
|
} else {
|
||||||
hostname = strings.Replace(hostname, "localhost", virtualhost, 1)
|
hostname = strings.Replace(hostname, "localhost", virtualhost, 1)
|
||||||
}
|
}
|
||||||
|
|
4
http.go
4
http.go
|
@ -1309,7 +1309,7 @@ type (
|
||||||
api *muxAPI
|
api *muxAPI
|
||||||
errorHandlers map[int]Handler
|
errorHandlers map[int]Handler
|
||||||
logger *logger.Logger
|
logger *logger.Logger
|
||||||
// the main server host's name, ex: localhost, 127.0.0.1, iris-go.com
|
// the main server host's name, ex: localhost, 127.0.0.1, 0.0.0.0, iris-go.com
|
||||||
hostname string
|
hostname string
|
||||||
// if any of the trees contains not empty subdomain
|
// if any of the trees contains not empty subdomain
|
||||||
hosts bool
|
hosts bool
|
||||||
|
@ -1328,7 +1328,7 @@ func newServeMux(contextPool sync.Pool, logger *logger.Logger) *serveMux {
|
||||||
cPool: &contextPool,
|
cPool: &contextPool,
|
||||||
lookups: make([]*route, 0),
|
lookups: make([]*route, 0),
|
||||||
errorHandlers: make(map[int]Handler, 0),
|
errorHandlers: make(map[int]Handler, 0),
|
||||||
hostname: "127.0.0.1",
|
hostname: config.DefaultServerHostname, // these are changing when the server is up
|
||||||
escapePath: !config.DefaultDisablePathEscape,
|
escapePath: !config.DefaultDisablePathEscape,
|
||||||
correctPath: !config.DefaultDisablePathCorrection,
|
correctPath: !config.DefaultDisablePathCorrection,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
|
|
@ -73,7 +73,7 @@ func TestServerHost(t *testing.T) {
|
||||||
var server1, server2, server3 Server
|
var server1, server2, server3 Server
|
||||||
var expectedHost1 = "mydomain.com:1993"
|
var expectedHost1 = "mydomain.com:1993"
|
||||||
var expectedHost2 = "mydomain.com:80"
|
var expectedHost2 = "mydomain.com:80"
|
||||||
var expectedHost3 = "127.0.0.1:9090"
|
var expectedHost3 = config.DefaultServerHostname + ":9090"
|
||||||
server1.Config.ListeningAddr = expectedHost1
|
server1.Config.ListeningAddr = expectedHost1
|
||||||
server2.Config.ListeningAddr = "mydomain.com"
|
server2.Config.ListeningAddr = "mydomain.com"
|
||||||
server3.Config.ListeningAddr = ":9090"
|
server3.Config.ListeningAddr = ":9090"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user