diff --git a/app/servers.go b/app/servers.go index 533ec49f0..b961b8892 100644 --- a/app/servers.go +++ b/app/servers.go @@ -69,7 +69,7 @@ func (app *CortezaApp) mountHttpRoutes(r chi.Router) { return } - r.Route(options.CleanBase(ho.WebappBaseUrl), webapp.MakeWebappServer(app.Log, ho, app.Opt.Auth)) + r.Route(options.CleanBase(ho.WebappBaseUrl), webapp.MakeWebappServer(app.Log, ho, app.Opt.Auth, app.Opt.Discovery)) app.Log.Info( "client web applications enabled", diff --git a/pkg/options/discovery.gen.go b/pkg/options/discovery.gen.go index ce2c52f1d..010bc278f 100644 --- a/pkg/options/discovery.gen.go +++ b/pkg/options/discovery.gen.go @@ -13,6 +13,7 @@ type ( Enabled bool `env:"DISCOVERY_ENABLED"` Debug bool `env:"DISCOVERY_DEBUG"` CortezaDomain string `env:"DISCOVERY_CORTEZA_DOMAIN"` + BaseUrl string `env:"DISCOVERY_BASE_URL"` } ) @@ -22,6 +23,7 @@ func Discovery() (o *DiscoveryOpt) { Enabled: false, Debug: false, CortezaDomain: "", + BaseUrl: "", } fill(o) diff --git a/pkg/options/discovery.yaml b/pkg/options/discovery.yaml index cd7f7b505..467c19d95 100644 --- a/pkg/options/discovery.yaml +++ b/pkg/options/discovery.yaml @@ -1,5 +1,5 @@ props: - - name: Enabled + - name: enabled type: bool default: false description: Enable discovery endpoints @@ -10,8 +10,14 @@ props: docs: description: Enable debug activity logging. - - name: CortezaDomain + - name: cortezaDomain type: string default: "" docs: description: Provides host of corteza compose webapp. + + - name: baseUrl + type: string + default: "" + docs: + description: Provides host of corteza server discovery. diff --git a/pkg/webapp/serve.go b/pkg/webapp/serve.go index eeaa4a32a..cf0560741 100644 --- a/pkg/webapp/serve.go +++ b/pkg/webapp/serve.go @@ -20,10 +20,11 @@ var ( baseHrefMatcher = regexp.MustCompile(``) ) -func MakeWebappServer(log *zap.Logger, httpSrvOpt options.HTTPServerOpt, authOpt options.AuthOpt) func(r chi.Router) { +func MakeWebappServer(log *zap.Logger, httpSrvOpt options.HTTPServerOpt, authOpt options.AuthOpt, discoveryOpt options.DiscoveryOpt) func(r chi.Router) { var ( - apiBaseUrl = options.CleanBase(httpSrvOpt.BaseUrl, httpSrvOpt.ApiBaseUrl) - apps = strings.Split(httpSrvOpt.WebappList, ",") + apiBaseUrl = options.CleanBase(httpSrvOpt.BaseUrl, httpSrvOpt.ApiBaseUrl) + discoveryApiBaseUrl = options.CleanBase(discoveryOpt.BaseUrl) + apps = strings.Split(httpSrvOpt.WebappList, ",") appIndexHTMLs = make(map[string][]byte) @@ -48,12 +49,12 @@ func MakeWebappServer(log *zap.Logger, httpSrvOpt options.HTTPServerOpt, authOpt for _, app := range apps { webBaseUrl = options.CleanBase(httpSrvOpt.WebappBaseUrl, app) - serveConfig(r, webBaseUrl, apiBaseUrl, authOpt.BaseURL, httpSrvOpt.BaseUrl) + serveConfig(r, webBaseUrl, apiBaseUrl, authOpt.BaseURL, httpSrvOpt.BaseUrl, discoveryApiBaseUrl) r.Get(webBaseUrl+"*", serveIndex(httpSrvOpt, appIndexHTMLs[app], fs)) } webBaseUrl = options.CleanBase(httpSrvOpt.WebappBaseUrl) - serveConfig(r, webBaseUrl, apiBaseUrl, authOpt.BaseURL, httpSrvOpt.BaseUrl) + serveConfig(r, webBaseUrl, apiBaseUrl, authOpt.BaseURL, httpSrvOpt.BaseUrl, discoveryApiBaseUrl) r.Get(webBaseUrl+"*", serveIndex(httpSrvOpt, appIndexHTMLs[""], fs)) } } @@ -94,12 +95,13 @@ func serveIndex(opt options.HTTPServerOpt, indexHTML []byte, serve http.Handler) } } -func serveConfig(r chi.Router, appUrl, apiBaseUrl, authBaseUrl, webappBaseUrl string) { +func serveConfig(r chi.Router, appUrl, apiBaseUrl, authBaseUrl, webappBaseUrl, discoveryApiBaseUrl string) { r.Get(options.CleanBase(appUrl, "config.js"), func(w http.ResponseWriter, r *http.Request) { const line = "window.%s = '%s';\n" _, _ = fmt.Fprintf(w, line, "CortezaAPI", apiBaseUrl) _, _ = fmt.Fprintf(w, line, "CortezaAuth", authBaseUrl) _, _ = fmt.Fprintf(w, line, "CortezaWebapp", webappBaseUrl) + _, _ = fmt.Fprintf(w, line, "CortezaDiscoveryAPI", discoveryApiBaseUrl) }) }