diff --git a/route.go b/route.go index e5a55e10..fd063e3f 100644 --- a/route.go +++ b/route.go @@ -223,8 +223,7 @@ func (r *Route) ParseURI(args ...interface{}) (uri string) { scheme = "https://" } - host := r.station.server.Host() - + host := r.station.server.VirtualHost() arguments := args[0:] // join arrays as arguments diff --git a/server/server.go b/server/server.go index 8bf2e8c4..6a1966be 100644 --- a/server/server.go +++ b/server/server.go @@ -67,6 +67,21 @@ func (s *Server) Host() (host string) { } } +// VirtualHost returns the s.Config.ListeningAddr, if host provided else returns the Listener's (Host()) +// +// Note: currently this is used only on iris/route.ParseURI. +// +func (s *Server) VirtualHost() (host string) { + // we always have at least the :PORT because of parseAddr, so we just + // check if we have anything before PORT + a := s.Config.ListeningAddr + if len(a[0:strings.IndexByte(a, ':')]) > 0 { + return a + } else { + return s.Host() + } +} + // Hostname returns the hostname part only, if host == 0.0.0.0:8080 it will return the 0.0.0.0 // if server is not listening it returns the config.ListeningAddr's hostname part func (s *Server) Hostname() (hostname string) {