-
Notifications
You must be signed in to change notification settings - Fork 5
feat: update OpenFeature React example #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
missionmike
wants to merge
7
commits into
Flagsmith:main
Choose a base branch
from
missionmike:feat/openfeature-react-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1798c85
feat: setup .env support, update deps.
missionmike 15e9fd2
feat: eject, use vite.
missionmike 8f5800f
feat: update dependencies, remove unused dependencies.
missionmike 6ba22d5
docs: update readme.
missionmike f41ffe0
feat: add .nvmrc.
missionmike a98b10d
feat: document in code.
missionmike 5f46bdd
feat: reorder import and document.
missionmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 @@ | ||
# Copy this file to a new file ".env" and update with | ||
# the client-side key you create from your own account. | ||
REACT_APP_FLAGSMITH_ENVIRONMENT_ID="YOUR_FLAGSMITH_CLIENT_SIDE_ENVIRONMENT_KEY" | ||
|
||
# If you're using a different Flagsmith endpoint (for example, | ||
# using a local docker compose container), set it here. | ||
REACT_APP_FLAGSMITH_API="https://edge.api.flagsmith.com/api/v1/flags/" |
This file contains hidden or 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
This file contains hidden or 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 @@ | ||
v22 |
This file contains hidden or 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,3 @@ | ||
{ | ||
"proseWrap": "always" | ||
} |
This file contains hidden or 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,20 +1,29 @@ | ||
<img width="100%" src="https://raw.githubusercontent.com/Flagsmith/flagsmith/main/static-files/hero.png"/> | ||
|
||
## Flagsmith with React and OpenFeature | ||
# Flagsmith with React and OpenFeature | ||
|
||
## Setup | ||
|
||
## Available Scripts | ||
To set up your local environment, first copy `.env.example` to `.env` and | ||
populate your Flagsmith environment ID. Optionally, specify the API endpoint | ||
that you want to use to retrieve the value of your feature flags. | ||
|
||
> Note: if you attempt to run the development environment without populating the | ||
> `.env` file correctly, you will encounter an error in the terminal. | ||
|
||
In the project directory, you can run: | ||
## Available Scripts | ||
|
||
### `npm start` | ||
In the project directory, you can run `npm start` to run the app in the | ||
development mode. | ||
|
||
Runs the app in the development mode.\ | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
This should attempt to open [http://localhost:3000](http://localhost:3000) to | ||
view it in the browser. | ||
|
||
The page will reload if you make edits.\ | ||
You will also see any lint errors in the console. | ||
The page will reload if you make edits. You will also see any lint errors in the | ||
console. | ||
|
||
## OpenFeature | ||
|
||
Please refer to the OpenFeature Documentation](https://openfeature.dev/docs/reference/technologies/client/web/react) for further information. | ||
Please refer to the OpenFeature | ||
Documentation](https://openfeature.dev/docs/reference/technologies/client/web/react) | ||
for further information. |
This file contains hidden or 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,38 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
try { | ||
/** | ||
* Checks if the .env file exists. | ||
*/ | ||
const envPath = path.join(process.cwd(), ".env"); | ||
if (!fs.existsSync(envPath)) { | ||
console.error("\x1b[31m%s\x1b[0m", "Error: .env file not found!"); | ||
console.error( | ||
"\x1b[33m%s\x1b[0m", | ||
"Please copy .env.example to .env and configure your environment variables." | ||
); | ||
console.error("\x1b[36m%s\x1b[0m", "You can do this by running:"); | ||
console.error("\x1b[37m%s\x1b[0m", "cp .env.example .env"); | ||
process.exit(1); | ||
} | ||
|
||
/** | ||
* Checks if the Flagsmith environment key has been configured. | ||
*/ | ||
const envContent = fs.readFileSync(envPath, "utf8"); | ||
if (envContent.includes("YOUR_FLAGSMITH_CLIENT_SIDE_ENVIRONMENT_KEY")) { | ||
console.error( | ||
"\x1b[31m%s\x1b[0m", | ||
"Error: Flagsmith environment key not configured!" | ||
); | ||
console.error( | ||
"\x1b[33m%s\x1b[0m", | ||
"Please replace YOUR_FLAGSMITH_CLIENT_SIDE_ENVIRONMENT_KEY in your .env file with your actual Flagsmith environment key." | ||
); | ||
process.exit(1); | ||
} | ||
} catch (err) { | ||
console.error("Error checking for .env file:", err); | ||
process.exit(1); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I grabbed the favicon from the main Flagsmith repo. |
Binary file not shown.
This file contains hidden or 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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta name="description" content="OpenFeature React Demo" /> | ||
<title>OpenFeature React Demo</title> | ||
<script type="module" src="src/index"></script> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For prettier formatting (automatic line wrap) on
.md
files.