1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

feat: share context between both frontend apis (#6529)

We are sharing contexts because we want both clients to use same session
ID.
This commit is contained in:
Jaanus Sellin 2024-03-13 11:17:40 +02:00 committed by GitHub
parent 259fde09db
commit 570af43615
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -36,5 +36,6 @@ export function createContext(value: any): Context {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const enrichContextWithIp = (query: any, ip: string): Context => {
query.remoteAddress = query.remoteAddress || ip;
query.sessionId = query.sessionId || String(Math.random());
return createContext(query);
};

View File

@ -179,14 +179,15 @@ export default class FrontendAPIController extends Controller {
let toggles: FrontendApiFeatureSchema[];
let newToggles: FrontendApiFeatureSchema[] = [];
if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) {
const context = FrontendAPIController.createContext(req);
[toggles, newToggles] = await Promise.all([
this.services.frontendApiService.getFrontendApiFeatures(
req.user,
FrontendAPIController.createContext(req),
context,
),
this.services.frontendApiService.getNewFrontendApiFeatures(
req.user,
FrontendAPIController.createContext(req),
context,
),
]);
const sortedToggles = toggles.sort((a, b) =>
@ -201,9 +202,10 @@ export default class FrontendAPIController extends Controller {
toggles.length
}, new count ${newToggles.length}, projects ${
req.user.projects
}, environment ${req.user.environment}, diff ${diff(
sortedToggles,
sortedNewToggles,
}, environment ${
req.user.environment
}, diff ${JSON.stringify(
diff(sortedToggles, sortedNewToggles),
)}`,
);
}