From 33d6a3360ba3544b08c110b1dae2e67c04136b9e Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Tue, 7 Nov 2023 13:19:39 +0800 Subject: [PATCH] feat: support api prefix for graphql playground --- graphql-server/go-server/main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/graphql-server/go-server/main.go b/graphql-server/go-server/main.go index acc3adc54..0b7515839 100644 --- a/graphql-server/go-server/main.go +++ b/graphql-server/go-server/main.go @@ -22,6 +22,7 @@ import ( "fmt" "log" "net/http" + "strings" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/handler" @@ -41,8 +42,9 @@ var ( host = flag.String("host", "", "bind to the host, default is 0.0.0.0") port = flag.Int("port", 8081, "service listening port") - enablePlayground = flag.Bool("enable-playground", false, "enable the graphql playground") - enableOIDC = flag.Bool("enable-oidc", false, "enable oidc authorization") + enablePlayground = flag.Bool("enable-playground", false, "enable the graphql playground") + enableOIDC = flag.Bool("enable-oidc", false, "enable oidc authorization") + playgroundEndpointPrefix = flag.String("playground-endpoint-prefix", "", "this parameter should also be configured when the service is forwarded via ingress and a path prefix is configured to avoid not finding the service, such as /apis") // Flags fro oidc client issuerURL = flag.String("issuer-url", "", "oidc issuer url(required when enable odic)") @@ -70,7 +72,13 @@ func main() { }) if *enablePlayground { - http.Handle("/", playground.Handler("Arcadia-Graphql-Server", "/bff")) + endpoint := "/bff" + if *playgroundEndpointPrefix != "" { + if prefix := strings.TrimPrefix(strings.TrimSuffix(*playgroundEndpointPrefix, "/"), "/"); prefix != "" { + endpoint = fmt.Sprintf("/%s%s", prefix, endpoint) + } + } + http.Handle("/", playground.Handler("Arcadia-Graphql-Server", endpoint)) } if *enableOIDC {