Can't use fetch() when using SSR #12064
-
I'm using SvelteKit to render static HTML that is served by my custom backend (Litestar) and I want to fetch some data from it on load. However, when I'm using fetch() in
I can workaround this issue by putting it inside something, like setInterval, but it doesn't work for stuff that I want to fetch once, on page load that is variable on the server side. Can someone help? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm assuming the error is due to the use of the Node.js Instead, you should fetch the data inside a SvelteKit |
Beta Was this translation helpful? Give feedback.
I'm assuming the error is due to the use of the Node.js
fetch
(server-side fetch) with a relative URL ("/data/started-time"?). Only browsers can make relative URL fetch requests. On the server, it must be an absolute URL (e.g., http://localhost:8000/data/started-time).Instead, you should fetch the data inside a SvelteKit
load
function. Read more: