14 lines
427 B
TypeScript
14 lines
427 B
TypeScript
const getBaseUrl = async () => {
|
|
const port = await window.audio.getPort();
|
|
if (port.error || !port.port) {
|
|
return `http://localhost:5010`;
|
|
}
|
|
// You can store the base URL in localStorage, a config file, or state
|
|
return `http://localhost:${port.port}`;
|
|
};
|
|
|
|
export default async function apiFetch(endpoint: string, options = {}) {
|
|
const url = `${await getBaseUrl()}/${endpoint}`;
|
|
return fetch(url, options);
|
|
}
|