Using SvelteKit, I have the following component:
/index.svelte
<script lang="ts">
$: {
fetchEndpoint();
}
async function fetchEndpoint() {
try {
const res = await fetch('/api/demo');
} catch(e) {
console.log(`Failed load endpoint. ${e}`);
}
}
</script>
/api/demo.ts
export async function get() {
return {
status: 200,
body: 'Hi',
};
}
On the first load of the page I get the following error message:
Failed load endpoint. TypeError [ERR_INVALID_URL]: Invalid URL
Why exactly is that and how can it be fixed?