diff --git a/framework/vendure/fetcher.ts b/framework/vendure/fetcher.ts index d980b9c90..bf8f0dcd8 100644 --- a/framework/vendure/fetcher.ts +++ b/framework/vendure/fetcher.ts @@ -24,7 +24,9 @@ export const fetcher: Fetcher = async ({ query, body: bodyObj, }) => { - const shopApiUrl = process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL + const shopApiUrl = + process.env.NEXT_PUBLIC_VENDURE_LOCAL_URL || + process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL if (!shopApiUrl) { throw new Error( 'The Vendure Shop API url has not been provided. Please define NEXT_PUBLIC_VENDURE_SHOP_API_URL in .env.local' diff --git a/next.config.js b/next.config.js index e17d3e5c4..9d6a29ba1 100644 --- a/next.config.js +++ b/next.config.js @@ -8,6 +8,7 @@ const provider = commerce.provider || getProviderName() const isBC = provider === 'bigcommerce' const isShopify = provider === 'shopify' const isSwell = provider === 'swell' +const isVendure = provider === 'vendure' module.exports = withCommerceConfig({ commerce, @@ -17,7 +18,7 @@ module.exports = withCommerceConfig({ }, rewrites() { return [ - (isBC || isShopify || isSwell) && { + (isBC || isShopify || isSwell || isVendure) && { source: '/checkout', destination: '/api/bigcommerce/checkout', }, @@ -27,6 +28,13 @@ module.exports = withCommerceConfig({ source: '/logout', destination: '/api/bigcommerce/customers/logout?redirect_to=/', }, + // For Vendure, rewrite the local api url to the remote (external) api url. This is required + // to make the session cookies work. + isVendure && + process.env.NEXT_PUBLIC_VENDURE_LOCAL_URL && { + source: `${process.env.NEXT_PUBLIC_VENDURE_LOCAL_URL}/:path*`, + destination: `${process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL}/:path*`, + }, // Rewrites for /search { source: '/search/designers/:name',