mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Use env var for Shop API url
This commit is contained in:
parent
eb7286f8e3
commit
449d331e41
@ -3,11 +3,11 @@ import fetchGraphqlApi from './utils/fetch-graphql-api'
|
|||||||
|
|
||||||
export interface VendureConfig extends CommerceAPIConfig {}
|
export interface VendureConfig extends CommerceAPIConfig {}
|
||||||
|
|
||||||
const API_URL = process.env.VENDURE_SHOP_API_URL
|
const API_URL = process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL
|
||||||
|
|
||||||
if (!API_URL) {
|
if (!API_URL) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The environment variable VENDURE_SHOP_API_URL is missing and it's required to access your store`
|
`The environment variable NEXT_PUBLIC_VENDURE_SHOP_API_URL is missing and it's required to access your store`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { ReactNode } from 'react'
|
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import {
|
import { ReactNode } from 'react'
|
||||||
CommerceConfig,
|
import { CommerceConfig, CommerceProvider as CoreCommerceProvider, useCommerce as useCoreCommerce } from '@commerce'
|
||||||
CommerceProvider as CoreCommerceProvider,
|
|
||||||
useCommerce as useCoreCommerce,
|
|
||||||
} from '@commerce'
|
|
||||||
import { FetcherError } from '@commerce/utils/errors'
|
import { FetcherError } from '@commerce/utils/errors'
|
||||||
|
|
||||||
async function getText(res: Response) {
|
async function getText(res: Response) {
|
||||||
@ -27,12 +23,21 @@ export const vendureConfig: CommerceConfig = {
|
|||||||
locale: 'en-us',
|
locale: 'en-us',
|
||||||
cartCookie: 'bc_cartId',
|
cartCookie: 'bc_cartId',
|
||||||
async fetcher({ url, method = 'POST', variables, query, body: bodyObj }) {
|
async fetcher({ url, method = 'POST', variables, query, body: bodyObj }) {
|
||||||
|
const shopApiUrl = 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')
|
||||||
|
}
|
||||||
const hasBody = Boolean(variables || query)
|
const hasBody = Boolean(variables || query)
|
||||||
const body = hasBody
|
const body = hasBody
|
||||||
? JSON.stringify({ query, variables })
|
? JSON.stringify({ query, variables })
|
||||||
: undefined
|
: undefined
|
||||||
const headers = hasBody ? { 'Content-Type': 'application/json' } : undefined
|
const headers = hasBody ? { 'Content-Type': 'application/json' } : undefined
|
||||||
const res = await fetch('http://localhost:3001/shop-api'!, { method, body, headers, credentials: 'include' })
|
const res = await fetch(shopApiUrl, {
|
||||||
|
method,
|
||||||
|
body,
|
||||||
|
headers,
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const { data } = await res.json()
|
const { data } = await res.json()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user