Skip to content

Conversation

greghuels
Copy link
Contributor

Motivation and Context

Allows users to override server-side flags by providing new parseOverrides and withOverrides functions to the EppoClient.

  • parseOverrides - Allows users to parse the x-eppo-overrides header sent by web requests. Eppo's Chrome extension will intercept and append this header to all https endpoints for the target site.
  • withOverrides - Creates an EppoClient instance that has overrides applied so that it doesn't affect the behavior of the original EppoClient singleton on a shared Node web server.

Typical usage will be something like this:

export const eppoOverridesStorage = new AsyncLocalStorage<Record<FlagKey, Variation>>();

@Injectable()
export class EppoOverridesMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    getInstance()
      .parseOverrides(req.headers['X-EPPO-OVERRIDES'] as string | undefined)
      .then((overrides) => eppoOverridesStorage.run(overrides, next))
      .catch(next);
  }
}

export const getEppoInstance = () => {
  const overrides = eppoOverridesStorage.getStore();
  return EppoSDK.getInstance().withOverrides(overrides);
};

How has this been tested?

  • Manual QA
  • Unit testing

@greghuels greghuels mentioned this pull request Mar 3, 2025
@greghuels greghuels force-pushed the greg/FF-4046/server-overrides branch from 114151d to f6b53f7 Compare March 3, 2025 17:06
@greghuels greghuels force-pushed the greg/FF-4046/server-overrides branch from f6b53f7 to c6f6837 Compare March 3, 2025 17:32
Copy link
Member

@leoromanovsky leoromanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very complete with the tests, thank you

Comment on lines +225 to +233
withOverrides(overrides: Record<FlagKey, Variation>): EppoClient {
if (overrides && Object.keys(overrides).length) {
const copy = shallowClone(this);
copy.overrideStore = new MemoryOnlyConfigurationStore<Variation>();
copy.overrideStore.setEntries(overrides);
return copy;
}
return this;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea to do this!

@greghuels greghuels merged commit a92ad46 into main Mar 3, 2025
8 checks passed
@greghuels greghuels deleted the greg/FF-4046/server-overrides branch March 3, 2025 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants