From 65df8036aee4f578802a7db6026e35c6d92160d4 Mon Sep 17 00:00:00 2001 From: Zaiste Date: Tue, 20 Apr 2021 16:31:52 +0200 Subject: [PATCH] fix: client/server pecularities for env visibility Must prefix with `NEXT_PUBLIC_` so that the API URL is visible on the client --- framework/commerce/config.js | 2 ++ framework/saleor/api/utils/fetch-graphql-api.ts | 6 +++++- framework/saleor/const.ts | 5 ++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/commerce/config.js b/framework/commerce/config.js index 0e962e2ef..9e9799528 100644 --- a/framework/commerce/config.js +++ b/framework/commerce/config.js @@ -18,6 +18,8 @@ function getProviderName() { ? 'shopify' : process.env.NEXT_PUBLIC_SWELL_STORE_ID ? 'swell' + : process.env.NEXT_PUBLIC_SALEOR_API_URL + ? 'saleor' : null) ) } diff --git a/framework/saleor/api/utils/fetch-graphql-api.ts b/framework/saleor/api/utils/fetch-graphql-api.ts index dfbcf0343..53675f766 100644 --- a/framework/saleor/api/utils/fetch-graphql-api.ts +++ b/framework/saleor/api/utils/fetch-graphql-api.ts @@ -3,13 +3,17 @@ import fetch from './fetch' import { API_URL } from '../../const' import { getError } from '../../utils/handle-fetch-response' +import { getConfig } from '..' const fetchGraphqlApi: GraphQLFetcher = async ( query: string, { variables } = {}, fetchOptions ) => { - const res = await fetch(API_URL, { + // FIXME @zaiste follow the bigcommerce example + const config = getConfig() + + const res = await fetch(API_URL || '', { ...fetchOptions, method: 'POST', headers: { diff --git a/framework/saleor/const.ts b/framework/saleor/const.ts index dea284d7f..506fccf8d 100644 --- a/framework/saleor/const.ts +++ b/framework/saleor/const.ts @@ -1,3 +1,2 @@ -export const API_URL = process.env.NEXT_SALEOR_API_URL - -export const API_CHANNEL = process.env.NEXT_SALEOR_CHANNEL +export const API_URL = process.env.NEXT_PUBLIC_SALEOR_API_URL +export const API_CHANNEL = process.env.NEXT_PUBLIC_SALEOR_CHANNEL