【发布时间】:2022-01-22 08:13:20
【问题描述】:
我正在尝试从 SvelteKit 访问我的 Shopify API,因此我使用了 .env:
VITE_SHOPIFY_STOREFRONT_API_TOKEN = ""
VITE_SHOPIFY_API_ENDPOINT = ""
它允许我配置整个环境。
然后我使用:
export const postToShopify = async ({ query, variables }) => {
try {
// @ts-ignore
const result = await fetch(import.meta.env.VITE_SHOPIFY_API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token': import.meta.env.VITE_SHOPIFY_STOREFRONT_API_TOKEN
},
body: JSON.stringify({ query, variables })
}).then((res) => res.json());
if (result.errors) {
console.log({ errors: result.errors });
} else if (!result || !result.data) {
console.log({ result });
return 'No results found.';
}
return result.data;
} catch (error) {
console.log(error);
}
};
但我不知道如何输入"VITE_SHOPIFY_API_ENDPOINT = """。
【问题讨论】:
-
提问或回答时请使用正确的语法。 SO 不是一个讨论板,它更像是一本问题及其答案的百科全书,其中语法很重要。请参阅How to Ask 和“Priority of grammar, spelling and punctuation in questions”。