【发布时间】:2021-07-24 20:05:41
【问题描述】:
在svelte.config.js里面我有这个:
preprocess: autoPreprocess({
replace: [
['API_ENDPOINT', JSON.stringify(process.env.API_ENDPOINT)]
]
}),
它应该替换字符串“API_ENDPOINT”,但不是。
这是我的使用方法:
async function api(url: string, body = {}, opts = {}) {
const endpoint = 'API_ENDPOINT';
console.log(endpoint);
const res = await fetch(endpoint + url, {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify(body)
});
if (!res.ok) {
const err = await res.json();
throw (err || res.statusText);
}
return opts.raw ? await res.text() : await res.json();
}
export default api;
我得到的只是http://localhost:3000/API_ENDPOINT/subscriptions
【问题讨论】:
标签: sveltekit