diff --git a/router/pkg/app/app.go b/router/pkg/app/app.go index dcb9562ac2..de7325aa13 100644 --- a/router/pkg/app/app.go +++ b/router/pkg/app/app.go @@ -388,9 +388,10 @@ func (a *App) newRouter(ctx context.Context, routerConfig *nodev1.RouterConfig) if a.playground { graphqlPlaygroundHandler := graphiql.NewPlayground(&graphiql.PlaygroundOptions{ - Log: a.logger, - Html: graphiql.GetGraphiqlPlaygroundHTML(), - NodeUrl: a.baseURL, + Log: a.logger, + Html: graphiql.GetGraphiqlPlaygroundHTML(), + // Empty url to use the same url as the playground + GraphqlURL: "", }) router.Get(a.graphqlPath, graphqlPlaygroundHandler) a.logger.Debug("PlaygroundHandler registered", diff --git a/router/pkg/config/config.go b/router/pkg/config/config.go index 986c7176a8..6820df6670 100644 --- a/router/pkg/config/config.go +++ b/router/pkg/config/config.go @@ -24,10 +24,10 @@ func (ipd *Base64Decoder) Decode(value string) error { type Config struct { FederatedGraphName string `envconfig:"FEDERATED_GRAPH_NAME" validate:"required"` - ControlplaneURL string `validate:"required" envconfig:"CONTROLPLANE_URL" validate:"uri"` + ControlplaneURL string `validate:"required" default:"https://cosmo-cp.wundergraph.com" envconfig:"CONTROLPLANE_URL" validate:"uri"` ListenAddr string `default:"localhost:3002" envconfig:"LISTEN_ADDR"` OTELTracingEnabled bool `default:"true" envconfig:"OTEL_TRACING_ENABLED"` - OTELCollectorEndpoint string `validate:"required" envconfig:"OTEL_COLLECTOR_ENDPOINT" validate:"uri"` + OTELCollectorEndpoint string `validate:"required" default:"https://cosmo-otel.wundergraph.com" envconfig:"OTEL_COLLECTOR_ENDPOINT" validate:"uri"` OTELCollectorHeaders map[string]string `default:"" envconfig:"OTEL_COLLECTOR_HEADERS"` OTELSampler float64 `default:"1" envconfig:"OTEL_SAMPLER"` OTELBatchTimeoutSeconds int `default:"5" envconfig:"OTEL_BATCH_TIMEOUT_SECONDS"` @@ -38,7 +38,7 @@ type Config struct { PrometheusHttpAddr string `default:"127.0.0.1:8088" envconfig:"PROMETHEUS_HTTP_ADDR"` CORSAllowedOrigins []string `default:"*" envconfig:"CORS_ALLOWED_ORIGINS"` CORSAllowedMethods []string `default:"HEAD,GET,POST" envconfig:"CORS_ALLOWED_METHODS"` - CORSAllowCredentials bool `default:"false" envconfig:"CORS_ALLOW_CREDENTIALS"` + CORSAllowCredentials bool `default:"true" envconfig:"CORS_ALLOW_CREDENTIALS"` CORSAllowedHeaders []string `default:"Origin,Content-Length,Content-Type" envconfig:"CORS_ALLOWED_HEADERS"` CORSMaxAgeMinutes int `default:"5" envconfig:"CORS_MAX_AGE_MINUTES"` PlaygroundEnabled bool `default:"true" envconfig:"PLAYGROUND_ENABLED"` diff --git a/router/pkg/graphiql/graphiql.html b/router/pkg/graphiql/graphiql.html index 8614430493..29d701e6c0 100644 --- a/router/pkg/graphiql/graphiql.html +++ b/router/pkg/graphiql/graphiql.html @@ -59,7 +59,7 @@ const generator = async function* () { const abort = new AbortController(); try { - const res = await fetch('{{apiURL}}/graphql', { + const res = await fetch('{{graphqlURL}}', { method: 'post', headers: { ...config.headers || {}, @@ -93,7 +93,7 @@ }; return generator(); } - return fetch('{{apiURL}}/graphql', { + return fetch('{{graphqlURL}}', { method: 'post', headers: { ...config.headers || {}, diff --git a/router/pkg/graphiql/playgroundhandler.go b/router/pkg/graphiql/playgroundhandler.go index 2516bffc6d..f4f3d28a25 100644 --- a/router/pkg/graphiql/playgroundhandler.go +++ b/router/pkg/graphiql/playgroundhandler.go @@ -8,14 +8,14 @@ import ( ) type PlaygroundOptions struct { - Log *zap.Logger - Html string - NodeUrl string + Log *zap.Logger + Html string + GraphqlURL string } func NewPlayground(opts *PlaygroundOptions) http.HandlerFunc { fn := func(w http.ResponseWriter, r *http.Request) { - tpl := strings.Replace(opts.Html, "{{apiURL}}", opts.NodeUrl, -1) + tpl := strings.Replace(opts.Html, "{{graphqlURL}}", opts.GraphqlURL, -1) resp := []byte(tpl) w.Header().Set("Content-Type", "text/html; charset=utf-8") diff --git a/router/pkg/graphiql/playgroundhandler_test.go b/router/pkg/graphiql/playgroundhandler_test.go index fb2600c02f..19031677cb 100644 --- a/router/pkg/graphiql/playgroundhandler_test.go +++ b/router/pkg/graphiql/playgroundhandler_test.go @@ -11,9 +11,9 @@ import ( func TestHealthCheckHandler(t *testing.T) { handler := NewPlayground(&PlaygroundOptions{ - Log: zap.NewNop(), - Html: "test {{apiURL}}", - NodeUrl: "http://localhost:8080", + Log: zap.NewNop(), + Html: "test {{graphqlURL}}", + GraphqlURL: "/", }) rec := httptest.NewRecorder() @@ -21,5 +21,5 @@ func TestHealthCheckHandler(t *testing.T) { assert.Equal(t, http.StatusOK, rec.Code) assert.Equal(t, "text/html; charset=utf-8", rec.Header().Get("Content-Type")) - assert.Equal(t, "test http://localhost:8080", rec.Body.String()) + assert.Equal(t, "test /", rec.Body.String()) }