-
Hi, super beginner here so sorry if this is a dumb question. For reference here is my directory structure
I'm using a private auth key to fetch bus arrival times at chosen bus stops in Example is here Can I avoid this? Can't really wrap my head around this. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Not a dumb question -- I had the same concern when first looking at SvelteKit. SvelteKit needs that In practice, I'm not sure how much of a concern this is. Though having a JSON endpoint makes it easier, people can still scrape your page's HTML for the data they need. However, there are a couple things you can do to make it more difficult to use the JSON endpoint:
const response = { stations: ["A", "B", "C"], otherInfo: { big: "object" } };
const data = { stations: response.stations }
return data; // "otherInfo" will not be exposed via __data.json
I think the // src/hooks.server.js
/** @type {import('@sveltejs/kit').[Handle](https://kit.svelte.dev/docs/types#public-types-handle)} */
export async function handle({ event, resolve }) {
// true when the request is for a `__data.json` endpoint
// https://kit.svelte.dev/docs/types#public-types-requestevent
if (event.isDataRequest) {
return new Response(null, { status: 400 });
}
const response = await resolve(event);
return response;
} If it were me, I would do 1 and not worry about 2, though YMMV. |
Beta Was this translation helpful? Give feedback.
Not a dumb question -- I had the same concern when first looking at SvelteKit. SvelteKit needs that
__data.json
endpoint to be available so it can fetch the data for a page when navigating. Other frameworks with client-side navigation and data loading (Remix, Next, Nuxt) do something similar. You can find more info in the glossary section of the docs.In practice, I'm not sure how much of a concern this is. Though having a JSON endpoint makes it easier, people can still scrape your page's HTML for the data they need. However, there are a couple things you can do to make it more difficult to use the JSON endpoint: