-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
211 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
NEXT_PUBLIC_APP_URL=https://${VERCEL_URL} | ||
|
||
FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
NEXT_PUBLIC_API_URL=http://api.devfaq.localhost:3002 | ||
NEXT_PUBLIC_APP_URL=http://app.devfaq.localhost:3000 | ||
|
||
FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import "server-only"; | ||
|
||
import Flagsmith from "flagsmith-nodejs"; | ||
import { BaseFlag } from "flagsmith-nodejs/build/sdk/models"; | ||
|
||
type Flag = "question_answers"; | ||
const defaultFlags: Record<Flag, BaseFlag> = { | ||
question_answers: { enabled: true, value: undefined, isDefault: true }, | ||
}; | ||
|
||
const getFlagsmith = async () => { | ||
if (!process.env.FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY) { | ||
console.warn(`FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY not provided.`); | ||
return null; | ||
} | ||
|
||
const flagsmith = new Flagsmith({ | ||
environmentKey: process.env.FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY, | ||
}); | ||
const flags = await flagsmith.getEnvironmentFlags(); | ||
return flags; | ||
}; | ||
|
||
const getFlag = async <F extends Flag>(flag: F) => { | ||
const flagsmith = await getFlagsmith(); | ||
if (!flagsmith) { | ||
return defaultFlags[flag]; | ||
} | ||
return flagsmith.getFlag(flag); | ||
}; | ||
|
||
export const isFlagEnabled = async <F extends Flag>(flag: F) => { | ||
return (await getFlag(flag)).enabled; | ||
}; |
Oops, something went wrong.