I am trying to figure out how to toggle a feature flag based on a custom context value. However, the LaunchDarkly docs aren't helpful.
I am using https://github.com/launchdarkly/node-server-sdk
An example would be:
I have feature flag that has an option to use cityContext
or countryContext
and I want to return true
if cityContext
was used as a rule within the feature flag.
I want to understand if the above is possible. As I want to perform custom logic depending on which context is used.
I have tried the following:
const cityContext = {
key: 'uuid',
custom: {
city: 'London'
}
}
const cityValue = await client.variation('any-value', cityContext, false);
const countryContext = {
key: 'uuid',
custom: {
country: 'United Kingdom'
}
}
const countryValue = await client.variation('any-value', countryContext, false);
You need to define a feature flag in LaunchDarkly and add a rule that assigns a user some variation based on a context:
Control
orTreatment
You can add different rules for instance:
Treatment 1
tocity=London
Treatment 2
tocountry=UK
Control