diff --git a/conf/defaults.ini b/conf/defaults.ini index bf0bf994b56..7e788e8daf7 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -89,6 +89,9 @@ cdn_url = # `0` means there is no timeout for reading the request. read_timeout = 0 +# Tell the backend server where to load frontend assets from when developing Grafana. +frontend_dev_server = + # This setting enables you to specify additional headers that the server adds to HTTP(S) responses. [server.custom_response_headers] #exampleHeader1 = exampleValue1 diff --git a/conf/sample.ini b/conf/sample.ini index da688f03078..deb1dabcc5d 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -92,6 +92,9 @@ # `0` means there is no timeout for reading the request. ;read_timeout = 0 +# Tell the backend server where to load frontend assets from when developing Grafana. +;frontend_dev_server = + # This setting enables you to specify additional headers that the server adds to HTTP(S) responses. [server.custom_response_headers] #exampleHeader1 = exampleValue1 diff --git a/pkg/api/dtos/index.go b/pkg/api/dtos/index.go index 6fa2d3766b8..d217db0fa8b 100644 --- a/pkg/api/dtos/index.go +++ b/pkg/api/dtos/index.go @@ -23,6 +23,7 @@ type IndexViewData struct { NewGrafanaVersion string AppName string AppNameBodyClass string + FrontendDevServer string FavIcon template.URL AppleTouchIcon template.URL AppTitle string diff --git a/pkg/api/index.go b/pkg/api/index.go index 32ff98532f2..75c356e4502 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -120,6 +120,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV ThemeType: theme.Type, AppUrl: appURL, AppSubUrl: appSubURL, + FrontendDevServer: hs.Cfg.FrontendDevServer, NewsFeedEnabled: hs.Cfg.NewsFeedEnabled, GoogleAnalyticsId: settings.GoogleAnalyticsId, GoogleAnalytics4Id: settings.GoogleAnalytics4Id, diff --git a/pkg/api/webassets/webassets.go b/pkg/api/webassets/webassets.go index 880c7e9f03d..335beae734c 100644 --- a/pkg/api/webassets/webassets.go +++ b/pkg/api/webassets/webassets.go @@ -43,23 +43,23 @@ func GetWebAssets(ctx context.Context, cfg *setting.Cfg, license licensing.Licen ret := entryPointAssetsCache entryPointAssetsCacheMu.RUnlock() - if cfg.Env == setting.Dev { + if cfg.Env == setting.Dev && cfg.FrontendDevServer != "" { // TODO: Hardcoded right now just to get vite dev env working. // see https://vitejs.dev/guide/backend-integration.html // Not sure we can rely on env config === dev alone as it's used in prod envs. viteDev := &dtos.EntryPointAssets{ JSFiles: []dtos.EntryPointAsset{ { - FilePath: "http://localhost:5173/@vite/client", + FilePath: fmt.Sprintf("%s/@vite/client", cfg.FrontendDevServer), Integrity: "", }, { - FilePath: "http://localhost:5173/app/index.ts", + FilePath: fmt.Sprintf("%s/app/index.ts", cfg.FrontendDevServer), Integrity: "", }, }, - Dark: "http://localhost:5173/sass/grafana.dark.scss", - Light: "http://localhost:5173/sass/grafana.light.scss", + Dark: fmt.Sprintf("%s/sass/grafana.dark.scss", cfg.FrontendDevServer), + Light: fmt.Sprintf("%s/sass/grafana.light.scss", cfg.FrontendDevServer), } return viteDev, nil diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index cc1b10b9054..8fc31627922 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -1886,6 +1886,8 @@ func (cfg *Cfg) readServerSettings(iniFile *ini.File) error { return fmt.Errorf("TLS version not configured correctly:%v, allowed values are TLS1.2 and TLS1.3", cfg.MinTLSVersion) } + // TODO: sanitize this for trailing slashes + cfg.FrontendDevServer = valueAsString(server, "frontend_dev_server", "") cfg.Domain = valueAsString(server, "domain", "localhost") cfg.HTTPAddr = valueAsString(server, "http_addr", DefaultHTTPAddr) cfg.HTTPPort = valueAsString(server, "http_port", "3000") diff --git a/public/views/index.html b/public/views/index.html index 58116cd2045..1a6a3ab5f2c 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -355,10 +355,10 @@ [[end]] - - [[ if .IsDevelopmentEnv ]] -