From 0c523359ebf7844fe7b7e25fa4da8e9be150401e Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Thu, 17 Oct 2024 09:35:02 +0530 Subject: [PATCH] Separate client and server urls. --- .../(storefront)/products/[handle]/ProductDetails.tsx | 2 +- src/app/(storefront)/products/[handle]/page.tsx | 2 +- src/app/(storefront)/products/page.tsx | 2 +- src/providers/cart.tsx | 10 +++++----- src/providers/customer.tsx | 8 ++++---- src/providers/region.tsx | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/app/(storefront)/products/[handle]/ProductDetails.tsx b/src/app/(storefront)/products/[handle]/ProductDetails.tsx index 5fe7dae..8784adf 100644 --- a/src/app/(storefront)/products/[handle]/ProductDetails.tsx +++ b/src/app/(storefront)/products/[handle]/ProductDetails.tsx @@ -39,7 +39,7 @@ const ProductDetails: FC = ({ handle }) => { region_id: region?.id as string, }); const products: HttpTypes.StoreProduct[] = await fetch( - `${process.env.NEXT_PUBLIC_BASE_URL}/store/products?${params}`, + `${process.env.NEXT_PUBLIC_STORE_URL}/store/products?${params}`, { credentials: 'include', headers: { diff --git a/src/app/(storefront)/products/[handle]/page.tsx b/src/app/(storefront)/products/[handle]/page.tsx index 8d53a60..d615cb7 100644 --- a/src/app/(storefront)/products/[handle]/page.tsx +++ b/src/app/(storefront)/products/[handle]/page.tsx @@ -10,7 +10,7 @@ interface ProductPageProps { } // export async function generateStaticParams() { // // Fetch the list of products -// const products: HttpTypes.StoreProduct[] = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/products`, { +// const products: HttpTypes.StoreProduct[] = await fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/products`, { // credentials: 'include', // headers: { // 'Content-Type': 'application/json', diff --git a/src/app/(storefront)/products/page.tsx b/src/app/(storefront)/products/page.tsx index 231e679..9aa8539 100644 --- a/src/app/(storefront)/products/page.tsx +++ b/src/app/(storefront)/products/page.tsx @@ -9,7 +9,7 @@ async function fetchProducts() { region_id: process.env.NEXT_PUBLIC_DEFAULT_REGION_ID as string, }); - const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/products?${params}`, { + const response = await fetch(`${process.env.NEXT_PRIVATE_BASE_URL}/store/products?${params}`, { credentials: 'include', headers: { 'Content-Type': 'application/json', diff --git a/src/providers/cart.tsx b/src/providers/cart.tsx index e7d7394..74c903d 100644 --- a/src/providers/cart.tsx +++ b/src/providers/cart.tsx @@ -32,7 +32,7 @@ export const CartProvider = ({ children }: CartProviderProps) => { const cartId = localStorage.getItem('cart_id'); if (!cartId) { // create a cart - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/carts`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/carts`, { method: 'POST', credentials: 'include', headers: { @@ -50,7 +50,7 @@ export const CartProvider = ({ children }: CartProviderProps) => { }); } else { // retrieve cart - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/carts/${cartId}`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/carts/${cartId}`, { credentials: 'include', headers: { 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY as string, @@ -73,7 +73,7 @@ export const CartProvider = ({ children }: CartProviderProps) => { return; } - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/carts/${cart.id}/line-items`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/carts/${cart.id}/line-items`, { credentials: 'include', method: 'POST', headers: { @@ -98,7 +98,7 @@ export const CartProvider = ({ children }: CartProviderProps) => { return; } - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/carts/${cart.id}/line-items/${item_id}`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/carts/${cart.id}/line-items/${item_id}`, { credentials: 'include', method: 'POST', headers: { @@ -122,7 +122,7 @@ export const CartProvider = ({ children }: CartProviderProps) => { return; } - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/carts/${cart.id}/line-items/${item_id}`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/carts/${cart.id}/line-items/${item_id}`, { credentials: 'include', headers: { 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY as string, diff --git a/src/providers/customer.tsx b/src/providers/customer.tsx index aa5c0a1..fa37414 100644 --- a/src/providers/customer.tsx +++ b/src/providers/customer.tsx @@ -122,7 +122,7 @@ export const CustomerProvider = ({ children }: CustomerProviderProps) => { }; const getJwt = async (email: string, password: string) => { try { - const { token } = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/auth/customer/emailpass`, { + const { token } = await fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/auth/customer/emailpass`, { credentials: 'include', method: 'POST', headers: { @@ -147,7 +147,7 @@ export const CustomerProvider = ({ children }: CustomerProviderProps) => { }; const registerEmail = async (email: string, password: string) => { try { - const { token } = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/auth/customer/emailpass/register`, { + const { token } = await fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/auth/customer/emailpass/register`, { credentials: 'include', method: 'POST', headers: { @@ -176,7 +176,7 @@ export const CustomerProvider = ({ children }: CustomerProviderProps) => { return; } // get customer - const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/customers/me`, { + const response = await fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/customers/me`, { credentials: 'include', headers: { 'Content-Type': 'application/json', @@ -198,7 +198,7 @@ export const CustomerProvider = ({ children }: CustomerProviderProps) => { return; } // create customer - const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/customers`, { + const response = await fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/customers`, { credentials: 'include', method: 'POST', headers: { diff --git a/src/providers/region.tsx b/src/providers/region.tsx index c9eea37..92b8812 100644 --- a/src/providers/region.tsx +++ b/src/providers/region.tsx @@ -28,7 +28,7 @@ export const RegionProvider = ({ children }: RegionProviderProps) => { const regionId = localStorage.getItem('region_id'); if (!regionId) { // retrieve regions and select the first one - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/regions`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/regions`, { credentials: 'include', headers: { 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY as string, @@ -40,7 +40,7 @@ export const RegionProvider = ({ children }: RegionProviderProps) => { }); } else { // retrieve selected region - fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/regions/${regionId}`, { + fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/regions/${regionId}`, { credentials: 'include', headers: { 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY as string,