Use proxy for vendure api

This commit is contained in:
Michael Bromley 2021-05-27 13:50:20 +02:00
parent 45c0f28639
commit cc1e7f90bd
2 changed files with 12 additions and 2 deletions

View File

@ -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'

View File

@ -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',