-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): pull release/v1.45.0 into main (#2712)
- Loading branch information
Showing
77 changed files
with
11,436 additions
and
9,532 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,49 @@ | ||
import { Context, Next } from 'koa'; | ||
|
||
export interface FeatureFlags { | ||
[key: string]: boolean | string; | ||
} | ||
|
||
export const FEATURE_FILTER_CODE = 'filter-code'; | ||
|
||
export default class FeatureFlagMiddleware { | ||
public static async handle(ctx: Context, next: Next): Promise<void> { | ||
// Initialize ctx.state.features if it doesn't exist | ||
ctx.state.features = (ctx.state.features || {}) as FeatureFlags; | ||
|
||
// Get headers from the request | ||
const { headers } = ctx.request; | ||
|
||
// Filter headers that start with 'X-Feature-' | ||
const featureHeaders = Object.keys(headers).filter((key) => | ||
key.toLowerCase().startsWith('x-feature-'), | ||
); | ||
|
||
// Convert feature headers to feature flags in ctx.state.features | ||
featureHeaders.forEach((featureHeader) => { | ||
// Get the feature name by removing the prefix, and convert to camelCase | ||
const featureName = featureHeader | ||
.substring(10) | ||
.replace(/X-Feature-/g, '') | ||
.toLowerCase(); | ||
|
||
let value: string | boolean | undefined; | ||
const valueString = headers[featureHeader] as string; | ||
if (valueString === 'true' || valueString === '?1') { | ||
value = true; | ||
} else if (valueString === 'false' || valueString === '?0') { | ||
value = false; | ||
} else { | ||
value = valueString; | ||
} | ||
|
||
// Set the feature flag in ctx.state.features | ||
if (value !== undefined) { | ||
ctx.state.features[featureName] = value; | ||
} | ||
}); | ||
|
||
// Move to the next middleware | ||
await next(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.