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 ( import (
"fmt" "fmt"
"strings"


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


if cfg.Default.Host != "" && cfg.Default.User != "" { 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 return cfg.Default.Host, nil
} }




Loading…
Cancel
Save