derschiw
derschiw

Reputation: 350

`index.json.js` endpoint - svelte kit

Using sveltekit I have and index.svelte file and I'm trying to call an endpoint called index.json.js like that:

<script context="module">
  export async function load({ params, fetch }) {
    const response = await fetch('/index.json');
    // ...
  }
</script>

Instead of calling the index.json.js endpoint, this calls the less specific [page].json.js endpoint. (When renaming the file to foo.json.js and await fetch('/foo.json'), it works).

I couldn't find anything about reserved keywords in the sveltekit documentation, so is there a reason for this behavior?

Thenks for helping me understand

Upvotes: 0

Views: 468

Answers (1)

brunnerh
brunnerh

Reputation: 185117

Looking at how the index gets contracted in examples, I tried just removing it like this:

await fetch('/.json');

It seems to call the correct endpoint that way.

Upvotes: 1

Related Questions