Skip to content

Commit a73fa3a

Browse files
committed
chore: improve the way we supply b2b cdn url
1 parent ab06c1b commit a73fa3a

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ B2B_API_HOST=https://api-b2b.bigcommerce.com
5151
BIGCOMMERCE_ACCESS_TOKEN=
5252

5353
# URL for the local buyer portal instance. Uncomment if developing locally.
54-
# LOCAL_BUYER_PORTAL_HOST=http://localhost:3001
54+
# LOCAL_BUYER_PORTAL_HOST=http://localhost:3001
55+
56+
# If you don't need local buyer portal but you need to work in a different environment
57+
# this variable will supply the correct microapps cdn url.
58+
# It will default to "production".
59+
# BUYER_PORTAL_ENVIRONMENT=production

core/b2b/loader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const EnvironmentSchema = z.object({
99
BIGCOMMERCE_STORE_HASH: z.string({ message: 'BIGCOMMERCE_STORE_HASH is required' }),
1010
BIGCOMMERCE_CHANNEL_ID: z.string({ message: 'BIGCOMMERCE_CHANNEL_ID is required' }),
1111
LOCAL_BUYER_PORTAL_HOST: z.string().url().optional(),
12-
STAGING_B2B_CDN_ORIGIN: z.string().optional(),
12+
BUYER_PORTAL_ENVIRONMENT: z.enum(['production', 'staging', 'integration']).optional().default('production'),
1313
});
1414

1515
export async function B2BLoader() {
1616
const {
1717
BIGCOMMERCE_STORE_HASH,
1818
BIGCOMMERCE_CHANNEL_ID,
1919
LOCAL_BUYER_PORTAL_HOST,
20-
STAGING_B2B_CDN_ORIGIN,
20+
BUYER_PORTAL_ENVIRONMENT,
2121
} = EnvironmentSchema.parse(process.env);
2222

2323
const session = await auth();
@@ -34,7 +34,7 @@ export async function B2BLoader() {
3434
);
3535
}
3636

37-
const environment = STAGING_B2B_CDN_ORIGIN === 'true' ? 'staging' : 'production';
37+
const environment = BUYER_PORTAL_ENVIRONMENT;
3838

3939
return (
4040
<ScriptProduction

core/b2b/script-production.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ interface Props {
99
storeHash: string;
1010
channelId: string;
1111
token?: string;
12-
environment: 'staging' | 'production';
12+
environment: 'staging' | 'production' | 'integration';
1313
cartId?: string | null;
1414
}
1515

1616
export function ScriptProduction({ cartId, storeHash, channelId, token, environment }: Props) {
1717
useB2BAuth(token);
1818
useB2BCart(cartId);
1919

20+
const CDN_BY_ENV: Record<Props['environment'], string> = {
21+
production: 'https://microapps.bigcommerce.com',
22+
staging: 'https://microapps.staging.zone',
23+
integration: 'https://microapps.integration.zone',
24+
};
25+
const src = `${CDN_BY_ENV[environment]}/b2b-buyer-portal/headless.js`;
26+
2027
return (
2128
<>
2229
<Script id="b2b-config">
@@ -35,7 +42,7 @@ export function ScriptProduction({ cartId, storeHash, channelId, token, environm
3542
data-channelid={channelId}
3643
data-environment={environment}
3744
data-storehash={storeHash}
38-
src={'https://microapps.bigcommerce.com/b2b-buyer-portal/headless.js'}
45+
src={src}
3946
type="module"
4047
/>
4148
</>

0 commit comments

Comments
 (0)