You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using sveltekit on the same host as an external api, fetching like this in load functions works -
(using sveltekit's fetch) fetch('/products/...')
that is, when in svelte.config.js paths.base is not set or set to ''.
If however the base path is set to something other than '', all server side requests (in load functions) to an 'external' path fail, making it impossible to ssr pages with calls to e.g. /api/... from /base/ .
Here is a minimal example.
Please note that this repo proxies requests to /products to dummyjson, to simulate an external api that has the same domain.
run npm run dev
click on 'navigate to someroute'
click on 'navigate to home/base'
reload home '/test' to prompt ssr
in svelte.config.js, change base to '', and repeat the last 3 steps.
Notice how ssr now works correctly.
Logs
No relevant logs. Request returns "Not Found" and 404 on the server side.
solves the issue.
Ofc, this is not a fix, but the root cause of the problem.
A request lands here, it has a base, but then the request does not start with 'base' so just 'Not found' is returned, even though there might be another app living on that route.
This also explains why this works when base is the empty string: this part is never executed. So the only thing i see that this code accomplishes is it doesn't allow access to routes lower than 'base', which conflicts with the browser behavior.
A sveltekit fetch() in the browser will happily respond with whatever is at a route other than 'base', whereas the server's fetch replication will just respond with 404 'Not found'.
edit:
it probably should look something more like this:
Describe the bug
When using sveltekit on the same host as an external api, fetching like this in load functions works -
(using sveltekit's fetch)
fetch('/products/...')
that is, when in svelte.config.js paths.base is not set or set to ''.
If however the base path is set to something other than '', all server side requests (in load functions) to an 'external' path fail, making it impossible to ssr pages with calls to e.g.
/api/...
from/base/
.Reproduction
https://github.com/thet0ast3r/kit-fetch-bug
Here is a minimal example.
Please note that this repo proxies requests to /products to dummyjson, to simulate an external api that has the same domain.
run
npm run dev
click on 'navigate to someroute'
click on 'navigate to home/base'
reload home '/test' to prompt ssr
in svelte.config.js, change base to '', and repeat the last 3 steps.
Notice how ssr now works correctly.
Logs
No relevant logs. Request returns "Not Found" and 404 on the server side.
This is the response object:
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: