diff --git a/superset-frontend/src/featureFlags.ts b/superset-frontend/src/featureFlags.ts index 1bac02dcb..8183cfa87 100644 --- a/superset-frontend/src/featureFlags.ts +++ b/superset-frontend/src/featureFlags.ts @@ -19,6 +19,7 @@ // We can codegen the enum definition based on a list of supported flags that we // check into source control. We're hardcoding the supported flags for now. export enum FeatureFlag { + ALLOW_DASHBOARD_DOMAIN_SHARDING = 'ALLOW_DASHBOARD_DOMAIN_SHARDING', OMNIBAR = 'OMNIBAR', CLIENT_CACHE = 'CLIENT_CACHE', SCHEDULED_QUERIES = 'SCHEDULED_QUERIES', @@ -49,7 +50,9 @@ declare global { } export function initFeatureFlags(featureFlags: FeatureFlagMap) { - window.featureFlags = featureFlags || {}; + if (!window.featureFlags) { + window.featureFlags = featureFlags || {}; + } } export function isFeatureEnabled(feature: FeatureFlag) { diff --git a/superset-frontend/src/utils/hostNamesConfig.js b/superset-frontend/src/utils/hostNamesConfig.js index a216cbee1..8a9f208cc 100644 --- a/superset-frontend/src/utils/hostNamesConfig.js +++ b/superset-frontend/src/utils/hostNamesConfig.js @@ -16,6 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +import { + initFeatureFlags, + isFeatureEnabled, + FeatureFlag, +} from 'src/featureFlags'; + function getDomainsConfig() { const appContainer = document.getElementById('app'); if (!appContainer) { @@ -23,8 +29,13 @@ function getDomainsConfig() { } const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap')); + // this module is a little special, it may be loaded before index.jsx, + // where window.featureFlags get initialized + // eslint-disable-next-line camelcase + initFeatureFlags(bootstrapData?.common?.feature_flags); const availableDomains = new Set([window.location.hostname]); if ( + isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING) && bootstrapData && bootstrapData.common && bootstrapData.common.conf && diff --git a/superset/config.py b/superset/config.py index fa5b3857f..d469b047b 100644 --- a/superset/config.py +++ b/superset/config.py @@ -298,6 +298,10 @@ LANGUAGES = {} # and FEATURE_FLAGS = { 'BAR': True, 'BAZ': True } in superset_config.py # will result in combined feature flags of { 'FOO': True, 'BAR': True, 'BAZ': True } DEFAULT_FEATURE_FLAGS: Dict[str, bool] = { + # allow dashboard to use sub-domains to send chart request + # you also need ENABLE_CORS and + # SUPERSET_WEBSERVER_DOMAINS for list of domains + "ALLOW_DASHBOARD_DOMAIN_SHARDING": True, # Experimental feature introducing a client (browser) cache "CLIENT_CACHE": False, "ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False,