diff --git a/client/graphql.go b/client/graphql.go index 3dacb8280bc9875e18c4eb0fda8b3908766833d6..6fabeadf085bb30aea7356e893ae0bc85856ea45 100644 --- a/client/graphql.go +++ b/client/graphql.go @@ -34,13 +34,7 @@ func Do(ctx context.Context, username string, svc string, query GraphQLQuery, result interface{}, ) error { conf := config.ForContext(ctx) - origin, _ := conf.Get(svc, "api-origin") - if origin == "" { - origin = config.GetOrigin(conf, svc, false) - } - if origin == "" { - panic(fmt.Errorf("No %s origin specified in config.ini", svc)) - } + origin := config.GetAPI(conf, svc, false) var ( contentType string diff --git a/config/config.go b/config/config.go index 0dbf1b3cbfba7d8376afa401794573ba4f76e305..2a88966bc8f9fae3ebfb37a77c285174b3c2554a 100644 --- a/config/config.go +++ b/config/config.go @@ -100,6 +100,11 @@ return config } +// Returns the URL (scheme, host, port) at which the web application for a +// given service can be found. +// +// Set "external" to true if the URL will be accessed by an external user (i.e. +// outside of the LAN). func GetOrigin(conf ini.File, svc string, external bool) string { if external { origin, _ := conf.Get(svc, "origin") @@ -111,6 +116,38 @@ return origin } origin, _ = conf.Get(svc, "origin") return origin +} + +// Returns the URL (scheme, host, port) at which the API for a given service +// can be found. Does not include the /query path! +// +// Set "external" to true if the URL will be accessed by an external user (i.e. +// outside of the LAN). +func GetAPI(conf ini.File, svc string, external bool) string { + var candidates []string + + if external { + candidates = []string{ + "api-origin", + "origin", + } + } else { + candidates = []string{ + "api-internal-origin", + "internal-origin", + "api-origin", + "origin", + } + } + + for _, name := range candidates { + origin, ok := conf.Get(svc, name) + if ok { + return origin + } + } + + panic(fmt.Errorf("No suitable origin configured for requested API")) } const DefaultQueueSize = 512