M client/graphql.go => client/graphql.go +1 -7
@@ 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
M config/config.go => config/config.go +37 -0
@@ 100,6 100,11 @@ func LoadConfig(defaultAddr string) ini.File {
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")
@@ 113,6 118,38 @@ func GetOrigin(conf ini.File, svc string, external bool) string {
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
// Returns the configured integer value for the given section and variable name.