From 8589d0f784c0c0f14ab310b28a7144b789689136 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Thu, 17 Oct 2024 08:15:46 +0530 Subject: [PATCH] Region id is now a environment variable fix hardcoding of localhost in cart --- src/app/(storefront)/products/page.tsx | 3 ++- src/lib/config.ts | 9 +-------- src/providers/cart.tsx | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/app/(storefront)/products/page.tsx b/src/app/(storefront)/products/page.tsx index 4d6105d..261bd25 100644 --- a/src/app/(storefront)/products/page.tsx +++ b/src/app/(storefront)/products/page.tsx @@ -17,8 +17,9 @@ export default function ProductsPage() { const params = new URLSearchParams({ // fields: `*variants.calculated_price`, fields: `*variants.prices.*`, - region_id: 'reg_01J988N552JQQZAJ7QJ3Y873QD', + region_id: process.env.NEXT_PUBLIC_DEFAULT_REGION_ID as string, }); + console.log('url: ', `${process.env.NEXT_PUBLIC_BASE_URL}/store/products?${params}`); fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/products?${params}`, { credentials: 'include', headers: { diff --git a/src/lib/config.ts b/src/lib/config.ts index b09b299..e8b272e 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1,14 +1,7 @@ import Medusa from '@medusajs/js-sdk'; -// Defaults to standard port for Medusa server -let MEDUSA_BACKEND_URL = 'http://localhost:9000'; - -if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) { - MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL; -} - export const sdk = new Medusa({ - baseUrl: MEDUSA_BACKEND_URL, + baseUrl: process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL as string, debug: process.env.NODE_ENV === 'development', publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY, }); diff --git a/src/providers/cart.tsx b/src/providers/cart.tsx index b4b1847..e7d7394 100644 --- a/src/providers/cart.tsx +++ b/src/providers/cart.tsx @@ -73,7 +73,7 @@ export const CartProvider = ({ children }: CartProviderProps) => { return; } - fetch(`http://localhost:9000/store/carts/${cart.id}/line-items`, { + fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/carts/${cart.id}/line-items`, { credentials: 'include', method: 'POST', headers: {