Skip to content

Commit

Permalink
Fix request group id to default to the request-id header (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle authored Feb 8, 2023
1 parent ef8bb1d commit 0b865a7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/hydrogen/src/storefront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export type CreateStorefrontClientOptions<TI18n extends I18nBase> = Parameters<
>[0] & {
cache?: Cache;
buyerIp?: string;
requestGroupId?: string;
requestGroupId?: string | null;
storefrontId?: string;
waitUntil?: ExecutionContext['waitUntil'];
i18n?: TI18n;
Expand Down Expand Up @@ -122,7 +122,7 @@ export function createStorefrontClient<TI18n extends I18nBase>({
waitUntil,
buyerIp,
i18n,
requestGroupId = generateUUID(),
requestGroupId,
storefrontId,
...clientOptions
}: CreateStorefrontClientOptions<TI18n>): StorefrontClient<TI18n> {
Expand All @@ -146,7 +146,8 @@ export function createStorefrontClient<TI18n extends I18nBase>({

const defaultHeaders = getHeaders({contentType: 'json'});

defaultHeaders[STOREFRONT_REQUEST_GROUP_ID_HEADER] = requestGroupId;
defaultHeaders[STOREFRONT_REQUEST_GROUP_ID_HEADER] =
requestGroupId || generateUUID();
if (buyerIp) defaultHeaders[STOREFRONT_API_BUYER_IP_HEADER] = buyerIp;
if (storefrontId) defaultHeaders[STOREFRONT_ID_HEADER] = storefrontId;

Expand Down
1 change: 1 addition & 0 deletions templates/demo-store/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default {
storeDomain: `https://${env.PUBLIC_STORE_DOMAIN}`,
storefrontApiVersion: env.PUBLIC_STOREFRONT_API_VERSION || '2023-01',
storefrontId: env.PUBLIC_STOREFRONT_ID,
requestGroupId: request.headers.get('request-id'),
});

/**
Expand Down
1 change: 1 addition & 0 deletions templates/hello-world/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default {
storeDomain: `https://${env.PUBLIC_STORE_DOMAIN}`,
storefrontApiVersion: env.PUBLIC_STOREFRONT_API_VERSION || '2023-01',
storefrontId: env.PUBLIC_STOREFRONT_ID,
requestGroupId: request.headers.get('request-id'),
});

/**
Expand Down
1 change: 1 addition & 0 deletions templates/skeleton/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default {
storeDomain: env.PUBLIC_STORE_DOMAIN,
storefrontApiVersion: env.PUBLIC_STOREFRONT_API_VERSION || '2022-10',
storefrontId: env.PUBLIC_STOREFRONT_ID,
requestGroupId: request.headers.get('request-id'),
});

/**
Expand Down

0 comments on commit 0b865a7

Please sign in to comment.