Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
fix env overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Prospector committed Jun 8, 2024
1 parent 9a2998f commit 9acbcc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions composables/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const COOKIE_OPTIONS: CookieOptions<PartialFeatureFlags> = {

export const useFeatureFlags = () =>
useState<AllFeatureFlags>('featureFlags', () => {
const config = useRuntimeConfig()

const savedFlags = useCookie<PartialFeatureFlags>('featureFlags', COOKIE_OPTIONS)

if (!savedFlags.value) {
Expand All @@ -76,6 +78,15 @@ export const useFeatureFlags = () =>

const flags: AllFeatureFlags = JSON.parse(JSON.stringify(DEFAULT_FEATURE_FLAGS))

const overrides = config.public.featureFlagOverrides as PartialFeatureFlags
for (const key in overrides) {
if (key in flags) {
const flag = key as FeatureFlag
const value = overrides[flag] as (typeof flags)[FeatureFlag]
flags[flag] = value
}
}

for (const key in savedFlags.value) {
if (key in flags) {
const flag = key as FeatureFlag
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function isProduction() {
}

function getFeatureFlagOverrides() {
return process.env.FLAG_OVERRIDES
return JSON.parse(process.env.FLAG_OVERRIDES ?? '{}')
}

function getDomain() {
Expand Down

0 comments on commit 9acbcc0

Please sign in to comment.