code: func (sc *serverCmd) fixURL(cfg config.Provider, s string, port int) (string, error) {
  	useLocalhost := false
  	if s == "" {
  		s = cfg.GetString("baseURL")
  		useLocalhost = true
  	}
  
  	if !strings.HasSuffix(s, "/") {
  		s = s + "/"
  	}
  
  	// do an initial parse of the input string
  	u, err := url.Parse(s)
  	if err != nil {
  		return "", err
  	}
  
  	// if no Host is defined, then assume that no schema or double-slash were
  	// present in the url.  Add a double-slash and make a best effort attempt.
  	if u.Host == "" && s != "/" {
  		s = "//" + s
  
  		u, err = url.Parse(s)
  		if err != nil {
  			return "", err
  		}
  	}
  
  	if useLocalhost {
  		if u.Scheme == "https" {
  			u.Scheme = "http"
  		}
  		u.Host = "localhost"
  	}
  
  	if sc.serverAppend {
  		if strings.Contains(u.Host, ":") {
  			u.Host, _, err = net.SplitHostPort(u.Host)
  			if err != nil {
  				return "", errors.Wrap(err, "Failed to split baseURL hostpost")
  			}
  		}
  		u.Host += fmt.Sprintf(":%d", port)
  	}
  
  	return u.String(), nil
  }
docs: // fixURL massages the baseURL into a form needed for serving
  // all pages correctly.