Browse Source

fix hostname schema dir issues

pull/36/head
Rob Loranger 4 years ago
parent
commit
83bc1cf310
No known key found for this signature in database GPG Key ID: D6F1633A4F0903B8
2 changed files with 15 additions and 1 deletions
  1. +9
    -1
      api/api.go
  2. +6
    -0
      config/options.go

+ 9
- 1
api/api.go View File

@@ -2,6 +2,7 @@ package api

import (
"fmt"
"strings"

"github.com/atotto/clipboard"
writeas "github.com/writeas/go-writeas/v2"
@@ -18,6 +19,9 @@ func HostURL(c *cli.Context) string {
return ""
}
insecure := c.Bool("insecure")
if parts := strings.Split(host, "://"); len(parts) > 1 {
host = parts[1]
}
scheme := "https://"
if insecure {
scheme = "http://"
@@ -35,7 +39,11 @@ func newClient(c *cli.Context) (*writeas.Client, error) {
if host := HostURL(c); host != "" {
clientConfig.URL = host + "/api"
} else if cfg.Default.Host != "" && cfg.Default.User != "" {
clientConfig.URL = "https://" + cfg.Default.Host + "/api"
if parts := strings.Split(cfg.Default.Host, "://"); len(parts) > 1 {
clientConfig.URL = cfg.Default.Host + "/api"
} else {
clientConfig.URL = "https://" + cfg.Default.Host + "/api"
}
} else if config.IsDev() {
clientConfig.URL = config.DevBaseURL + "/api"
} else if c.App.Name == "writeas" {


+ 6
- 0
config/options.go View File

@@ -95,10 +95,16 @@ func HostDirectory(c *cli.Context) (string, error) {
}
// flag takes precedence over defaults
if hostFlag := c.GlobalString("host"); hostFlag != "" {
if parts := strings.Split(hostFlag, "://"); len(parts) > 1 {
return parts[1], nil
}
return hostFlag, nil
}

if cfg.Default.Host != "" && cfg.Default.User != "" {
if parts := strings.Split(cfg.Default.Host, "://"); len(parts) > 1 {
return parts[1], nil
}
return cfg.Default.Host, nil
}



Loading…
Cancel
Save