I have a piece of data, like so: let jobPagesCount = 1 (on a client-side) and I need to send it over to an index.json.ts file, so I can use it there for fetching new data. This is supposed to happen when a user clicks a button. I tried:
button?.addEventListener('click', async () => {
return await fetch('/index.json', {
method: 'POST',
body: JSON.stringify({ jobPagesCount }),
headers: {
'Content-Type': 'application/json'
}
})
})
but I got an error in the console that says: "POST http://localhost:4321/index.json 404 (Not Found)", even though the endpoint seems to work correctly because when I type "http://localhost:4321/index.json" in the address bar, I can see the data that are currently fetched in there.
What am I doing wrong?