{{ url }} prepends with the listening address and not the real host

This commit is contained in:
Makis Maropoulos 2016-06-07 20:54:34 +03:00
parent 721e9ef66f
commit 2da67206c8
2 changed files with 16 additions and 2 deletions

View File

@ -223,8 +223,7 @@ func (r *Route) ParseURI(args ...interface{}) (uri string) {
scheme = "https://" scheme = "https://"
} }
host := r.station.server.Host() host := r.station.server.VirtualHost()
arguments := args[0:] arguments := args[0:]
// join arrays as arguments // join arrays as arguments

View File

@ -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 // 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 // if server is not listening it returns the config.ListeningAddr's hostname part
func (s *Server) Hostname() (hostname string) { func (s *Server) Hostname() (hostname string) {