-
Notifications
You must be signed in to change notification settings - Fork 2
Add server example #92
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
Closed
zhiyuanliang-ms
wants to merge
13
commits into
zhiyuanliang/targeting-context-accessor
from
zhiyuanliang/add-example
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7db4c1d
add server example
zhiyuanliang-ms 1e0e34e
update
zhiyuanliang-ms 8fd3ea7
Fix readme title (#95)
zhiyuanliang-ms d632aef
update
zhiyuanliang-ms 771c2b9
Use commonjs for node example in README (#96)
zhiyuanliang-ms a5710ac
update node example (#97)
zhiyuanliang-ms 1f8c1b2
version bump 2.0.1 (#99)
zhiyuanliang-ms 3ced7af
Bump serialize-javascript and mocha in /src/feature-management (#101)
dependabot[bot] 00794c6
add testcases & remove unused code (#94)
zhiyuanliang-ms f919243
update readme (#102)
zhiyuanliang-ms 81a48ba
update
zhiyuanliang-ms c5b05d4
Merge branch 'main' of https://github.com/microsoft/FeatureManagement…
zhiyuanliang-ms 3449505
Merge branch 'zhiyuanliang/targeting-context-accessor' into zhiyuanli…
zhiyuanliang-ms 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
Next
Next commit
add server example
- Loading branch information
commit 7db4c1d41cc2e19bac9a60af31973d70e4f6a0cf
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,31 @@ | ||
{ | ||
"feature_management": { | ||
"feature_flags": [ | ||
{ | ||
"id": "Beta", | ||
"enabled": true, | ||
"conditions": { | ||
"client_filters": [ | ||
{ | ||
"name": "Microsoft.Targeting", | ||
"parameters": { | ||
"Audience": { | ||
"Users": [ | ||
"Jeff" | ||
], | ||
"Groups": [ | ||
{ | ||
"Name": "Admin", | ||
"RolloutPercentage": 100 | ||
} | ||
], | ||
"DefaultRolloutPercentage": 40 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} |
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 @@ | ||
{ | ||
"dependencies": { | ||
"@azure/app-configuration-provider": "latest", | ||
"@microsoft/feature-management": "latest", | ||
"express": "^4.21.2" | ||
} | ||
} |
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,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Beta</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
text-align: center; | ||
background-color: #ffffff; | ||
color: #000000; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 75vh; | ||
} | ||
h1 { | ||
font-size: 5em; | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<h1>Welcome to the Beta page!</h1> | ||
</div> | ||
</body> | ||
</html> |
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,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Home</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
text-align: center; | ||
background-color: #ffffff; | ||
color: #000000; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 75vh; | ||
} | ||
h1 { | ||
font-size: 5em; | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<h1>Hello World!</h1> | ||
</div> | ||
</body> | ||
</html> |
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,63 @@ | ||
import express from "express"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import fs from 'node:fs/promises'; | ||
|
||
import { load } from "@azure/app-configuration-provider"; | ||
const connectionString = "<your-connection-string>";; | ||
const appConfig = await load(connectionString, { | ||
featureFlagOptions: { | ||
enabled: true, | ||
selectors: [{ | ||
keyFilter: "*" | ||
}], | ||
refresh: { | ||
enabled: true | ||
} | ||
} | ||
}); | ||
|
||
appConfig.onRefresh(() => { | ||
console.log("Configuration has been refreshed."); | ||
}); | ||
|
||
import { ConfigurationObjectFeatureFlagProvider, ConfigurationMapFeatureFlagProvider, FeatureManager } from "@microsoft/feature-management"; | ||
|
||
/* | ||
You can use either ConfigurationObjectFeatureFlagProvider or ConfigurationMapFeatureFlagProvider to provide feature flags. | ||
We recommend using Azure App Configuration as the source of feature flags. | ||
*/ | ||
// const config = JSON.parse(await fs.readFile("config.json")); | ||
// const featureProvider = new ConfigurationObjectFeatureFlagProvider(config); | ||
|
||
const featureProvider = new ConfigurationMapFeatureFlagProvider(appConfig); | ||
const featureManager = new FeatureManager(featureProvider); | ||
|
||
const app = express(); | ||
const PORT = 3000; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const pageDir = path.join(__dirname, "pages"); | ||
|
||
app.get("/", (req, res) => { | ||
appConfig.refresh(); | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res.sendFile(path.join(pageDir, "index.html")); | ||
}); | ||
|
||
|
||
app.get("/Beta", async (req, res) => { | ||
appConfig.refresh(); | ||
const { userId, groups } = req.query; | ||
|
||
if (await featureManager.isEnabled("Beta", { userId: userId, groups: groups ? groups.split(",") : [] })) { | ||
res.sendFile(path.join(pageDir, "beta.html")); | ||
} else { | ||
res.status(404).send("Page not found"); | ||
} | ||
}); | ||
|
||
|
||
// Start the server | ||
app.listen(PORT, () => { | ||
console.log(`Server is running at http://localhost:${PORT}`); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.