I'm creating a webapp with SvelteKit with a data source being a REST API on a separate server (Django + Django REST Framework). My understanding is that I can leave SSR enabled and just make fetch calls to my REST API endpoints. Should I make these calls from +page.ts or +page.server.ts?
What about if I use session auth with my Django backend and I need to send back the session data to the backend?
@kevlar what you're proposing is completely fine.
As the docs tell you the page.server.ts files makes most sense when you have secret environment variables or API keys.
https://kit.svelte.dev/docs/routing#page-page-server-js
In your case where it is an open API and you have no secrets to hide the +page.ts makes perfect sense.
The scenarios where this is important would for example be when you want to protect the calls to the API, environment variables or if you're using SvelteKit as your actual backend where it will connect to databases etc.
Hope it helps clarify :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With